+ 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.

28th Jul 2019, 9:04 PM
Learning Code
Learning Code - avatar
2 odpowiedzi
+ 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! 😄
28th Jul 2019, 9:30 PM
Anton Böhler
Anton Böhler - avatar
+ 1
Anton Bohler ..well explained
11th Aug 2019, 1:32 AM
SELFTEACH
SELFTEACH - avatar