Answer the question
In order to leave comments, you need to log in
Why doesn't if text == line work even though the output is text = a, line = a?
If you write code like this, then everything is fine.
for line in phrases_read:
if text in line.lower():
...
if text == line.lower():
...
Answer the question
In order to leave comments, you need to log in
If the `in` operator has both string arguments, then this operator returns the occurrence of the substring in the string. The letter "a" is in the word "car" and there is nothing surprising here. You are very careless and inaccurate in your question. You probably do not understand how operators work and do not know that when reading from a file, paragraph characters remain in the lines.
Give the value of the lines in full. You may not notice a paragraph if you are typing a line. type repr(text)
, there will be visible non-printable characters.
And if text = a, line = a, the code simply ignores this match
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question