+ 4

What is this that is not True? [Third question Boolean Logic]

The third question says: What is the result of this code? if not True: print("1") elif not (1 + 1 == 3): print("2") else: print("3") I wonder what is the object that the line is evaluating "if not True:" I mean, what is the object of which we can say is not true? How does Python understand that there is a value? If you try, for instance: if True: print("Yeah!") (the output is) Yeah! then I guess True is the boolean value of some object. What is the object if it is not explicit in the if statement? Here is a similar question here https://www.sololearn.com/Discuss/41385/why-does-it-begin-with-if-not-true , but for me is not completely clear. Thanks.

22nd Nov 2016, 12:46 AM
Estefania Barreto Ojeda
Estefania Barreto Ojeda - avatar
3 Antworten
+ 1
Remember not means 'not true', so the code will continue to run to the next line. What is the result of this code? if not True: <===is false, go to next line (will not print 1) print("1") elif not (1 + 1 == 3): <=== result is 2==3, not true, so if not true print 2. The code terminates here. print("2") else: print("3") I hope this helps!
1st Feb 2017, 10:00 PM
phil
phil - avatar
0
Ok, never mind. the thing is that when you type True you are defining the boolean value. Is not a variable, this is different. Thanks anyway.
22nd Nov 2016, 12:56 AM
Estefania Barreto Ojeda
Estefania Barreto Ojeda - avatar
0
True is a keyword not an object. https://docs.python.org/3/reference/lexical_analysis.html?highlight=True Thus, when you type True, you are possibly not defining anything. You are just telling True to the interpreter, the same way you do when you type 'if', 'def' or 'break'. However, there is some info about python boolean objects in python\c api reference: https://docs.python.org/3/c-api/bool.html
22nd Nov 2016, 5:13 PM
donkeyhot
donkeyhot - avatar