+ 4

I don't get the the code "if not True"

if not True: print("1") elif not (1 + 1 == 3): print("2") else: print("3")

11th Nov 2015, 2:30 PM
david
12 odpowiedzi
+ 4
it's written in the lesson: the result of "not true" is "False". So, if it's False, in an if statement, it is not executed (unless it the case in which it is a condition in an elif). I hope that I'm clear enough :p
23rd Nov 2015, 11:46 AM
Mickaël E.
Mickaël E. - avatar
+ 3
Only True conditions will be executed. The if statement is false(not True), so it is not executed. The elif statement is True (not(2==3)), hence it is executed and the answer is 2. Had both the statements been False, the else statement would be executed. I hope I've made my self clear.
20th Dec 2015, 10:58 AM
Vansh
Vansh - avatar
+ 2
Only "True" if or elif statements are executed. So when you have a statement say, "if False: " stop right there because anything in that if statement will not be executed. Same is the case with elif. for example; "elfi (2 == 3):" since 2 is not equal to 3 the elif has a False condition therefore no execution.
2nd Jan 2016, 12:41 AM
Waleed Kayani
Waleed Kayani - avatar
+ 2
"not True"is "false",so if statement goes to "else".
2nd Jan 2016, 3:50 AM
wubinbin
+ 2
"if True:" will effectively auto execute the if statement block because you are defining the condition as true without making a comparison. "if not True" translates to "if False". This will not execute the statements in this "if" block because you are defining the condition as false.
7th Jul 2016, 11:24 PM
mshumai
0
should it make an assumption first before saying the first line is not true???
7th Jul 2016, 2:57 AM
Eli Smith
Eli Smith - avatar
0
not clear at all.
7th Jul 2016, 3:35 AM
Eli Smith
Eli Smith - avatar
0
if what isn't true print "1"???? if what isn't true???
7th Jul 2016, 3:36 AM
Eli Smith
Eli Smith - avatar
- 1
didn't clearly understood the first line of code if not true should have executed, but it jumps to the next line of code.. puzzled I am
6th Jul 2016, 5:08 PM
Qusar Laskar
Qusar Laskar - avatar
- 1
Michael plz don't mind but you think you are clear your statements are not clear
23rd Sep 2016, 4:21 AM
Ahmed Kamal
Ahmed Kamal - avatar
- 1
vansh's arguments are stronger
23rd Sep 2016, 4:22 AM
Ahmed Kamal
Ahmed Kamal - avatar
- 1
i will try to explain it in other way. syntax is as follows if <statement>: print "true" else: print "false" now if the statement evaluates to true then statements inside if condition will execute. otherwise else part will get execute. In example you have mentioned above. The satement is <not true> is evaluated to false hence elif part will executed next hope you understands it
12th Nov 2016, 2:03 PM
Dhananjay
Dhananjay - avatar