+ 2
Python 3 == and if-else
Hello everybody I have been really confused on what the == sign does and im confused on the if statements and the else statements.
2 Respuestas
+ 4
the == tests if two 'things' (numbers, Strings, ...) are the same. When they are equal the result is True, when not the result is False.
example:
x = 3
y = (x == 3)
print(y)
z = (x == 2)
print(z)
In if-statments the indented block of code gets executed when the expretion is True. When it's False the else-block is executed, if there is one ...:
if True:
print("nice")
if False:
print("0")
else:
print("1")
The two can be combined:
x = 3
if x == 3:
print("nice")
else:
print("math doesnt work!")
hope this helped(/s)
happy coding! 😄
+ 1
Anton Bohler ..well explained