I came across a equality comparison problem in python 2.7. I ran the following program,expecting that elist[i][1] == MC
will return True
.
elist=elist=[[1,1],[2,4],[3,9]]
MC=0
while (MC<1.01):
MC+=0.01
for i in range(len(elist)):
#test equality
print elist[i][1]
print MC
print elist[i][1]==int(MC)
But it came out as:
1
1.0
False
4
1.0
False
9
1.0
False
Even I change into:
float(elist[i][1])==float(MC)
It still returns the same result.
Does anybody know why this happen?