jeudi 28 juillet 2016

Why do identical strings return false with ==?

This is the simplified version of my problem.

QA = open('Qestions and answers.txt')
Q = []
A = []

for line in QA:
  (first,second) = line.split(';')
   Q.append(first)
   A.append(second)

QA.close()

print(A[0], A[1])
print(A[0] == '1981')
print(A[1] == 'Feb')
print(str(A[0]) == '1981') # I even tried str
print(str(A[1]) == "Feb")

Output:

1981
 Feb

False
False
False
False

Aucun commentaire:

Enregistrer un commentaire