+ 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")
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
+ 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.
+ 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.
+ 2
"not True"is "false",so if statement goes to "else".
+ 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.
0
should it make an assumption first before saying the first line is not true???
0
not clear at all.
0
if what isn't true print "1"???? if what isn't true???
- 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
- 1
Michael plz don't mind but you think you are clear your statements are not clear
- 1
vansh's arguments are stronger
- 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