Explain how: if not True: print("1") elif not (1 + 1 == 3): print("2") Gives the output as 2 | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Explain how: if not True: print("1") elif not (1 + 1 == 3): print("2") Gives the output as 2

26th Oct 2016, 2:31 PM
Brave
1 Réponse
+ 2
The not operator inverts the value of a bool. not True is False, and not False is True. not True is False, so we don't enter the if block. not (1+1 == 3) is True (since (1+1 == 3) is False), so we enter the elif block and print 2.
26th Oct 2016, 2:45 PM
Zen
Zen - avatar