+ 4

Why does one method return False in one line and in another it doesn't (same method)

print(" " in string) #Program returns False if " " in string == False: # On the next line program ignores that fact and goes to else print("spaces were removed") else: print("An error occured") https://code.sololearn.com/c9c45cmGaLUY/?ref=app

1st Dec 2019, 9:10 AM
Adam Bernat
Adam Bernat - avatar
4 Respuestas
+ 9
Mistake is in the if statement, I guess you need to add "()" to give priority if (" " in string) == False: print("spaces were removed") else: print("An error occured")
1st Dec 2019, 9:16 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 2
You had right idea. Thanks
1st Dec 2019, 9:20 AM
Adam Bernat
Adam Bernat - avatar
0
if (" " in string) == False: it evaluate the first expression since it is false it does not check the second one. add parentheses like above. read about the order of evaluations in if statement.
1st Dec 2019, 9:20 AM
Bahhaⵣ
Bahhaⵣ - avatar