0

Boolean NoT operator Python

if not True : print ("1") elif not (1+1==3): print("2") else: print("3") Why did we use if not True: print("1") What is the use of coding it in the program, because when we compile it separately we get no output

29th Jul 2020, 5:33 AM
Yukthamukhi Rudra
Yukthamukhi Rudra - avatar
3 ответов
+ 1
Yukthamukhi Rudra This thing is self explanatory 😃😃 If something is not True, then it's False. If not True is used to make you do some work to know that the statement is False. Therefore, anything under a False statement will not be run, that's why you get no output. Hope this helps 😃😃
29th Jul 2020, 5:40 AM
Tomiwa Joseph
Tomiwa Joseph - avatar
0
"if not True" always returns False, so indeed the snippet has no effect during runtime. However, even though it may not be a good practice, you can use this kind of code to temporarily disable the following codes, which can be useful during debugging. e.g. if False: (some code you want to disable temporarily)
29th Jul 2020, 5:44 AM
Panko
Panko - avatar
0
Thanks Tomiwa and Panko:) That's was helpful :)
29th Jul 2020, 5:53 AM
Yukthamukhi Rudra
Yukthamukhi Rudra - avatar