+ 3

Why this code always evaluates the first elif statement as true?

I don't understand why this always evaluate only the first elif statement as true, this even when it should be evaluated as false and go to the next statement. I'm using Python 3 https://code.sololearn.com/clMh2gy56Plq/?ref=app

21st Jun 2020, 5:16 PM
Sebastian
Sebastian - avatar
4 ответов
+ 2
What do 'or' and 'and' statements do? They are called logical operators because they are used to connect two conditions, every condition or expression has a Boolean value, in the Boolean logic, everything rather than 0, "", [], None, False evaluates to True This means that 'a' or 'b' means True or True, while in: user == 'a' or user == 'b', both user == 'b' and user == 'a' can be either True or False depending on the situation, same thing applies in case of 'and' operator.
21st Jun 2020, 5:58 PM
Ali Abdelhady
Ali Abdelhady - avatar
+ 6
As already mentioned, syntax has to be: elif user == "a" or user == "b": # or could be also expressed like this: elif user in 'ab':
21st Jun 2020, 5:44 PM
Lothar
Lothar - avatar
+ 3
The syntax is: elif user == 'x' or user == 'y':
21st Jun 2020, 5:19 PM
Slick
Slick - avatar