# "Not" in an if statement

 2 What exactly does "not" mean in an an if statement? Does it mean to proceed to the next step only if the text expression is False instead of True? asked 04 Mar '12, 16:26 Elizabeth A.... 1.1k●24●71●107 accept rate: 4%

 3 Not changes True to False or False to True. If not True means If False, If not False - means If True. answered 04 Mar '12, 16:29 Andrius Sima... 605●1●6●21
 2 This has to do with boolean variables. 'not', as you point out, is the opposite. For example if (day is hot): # 'day is hot' is True: go surfing go surfing else: # 'day is hot' is False: go snowboarding go snowboarding  is exactly the same as if not (day is hot): # 'not (day is hot)' is True -> day is cold: snowboard go snowboarding else: go surfing # it is NOT True that 'day is not hot' -> day is hot: go surfing  You can combine the 3 boolean operators - not, and and or - to make very complex expressions. For example: if not(sick or busy) and not(is_raining or is_hailing or is_snowing) and ( (have money for gas) or (can get a ride)): go surfing  In this case, the expressions are evaluated like in math.. first evaluate the most inner parenthesis and work your way outwards. answered 04 Mar '12, 17:34 Goldsong 19.5k●29●111●104
 0 When we say if a or b: print "Hello!"  then Hello! will be printed if a is true or b is true (or both are true). When we say if not a: print "Hello!"  Then Hello! will be printed if a is not true. answered 04 Mar '12, 16:30 Anton Golov ♦ 13.3k●21●74●174 Format this differently please, it is unreadable, specially for beginners! -- thanks. (04 Mar '12, 17:16) Angel
 0 @LizP In essence, you got it right. if not a == b: print 'ok' would be the same as: if a != b: print 'ok' In both, 'ok' would be printed Furthermore, Python is one of those languages considering True a variable being assigned (I love this): x = 'toto' if not x: print 'ok' Here, 'ok' would not be printed as x is a string and is considered True, but 'not' revert it to False. answered 04 Mar '12, 17:18 Angel 7.0k●6●32●112 Uhm, not really. Python just has a bunch of "Truth-ish" and "False-ish" values. You'll find an empty list to be false, for example. An unassigned variable is, on the other hand, an exception. (04 Mar '12, 17:28) Anton Golov ♦ An unassigned variable is an error, is it not? (04 Mar '12, 17:29) Angel Yeah, sorry; an exception is just a fancy word for that. :) (04 Mar '12, 17:43) Anton Golov ♦
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

×15,294
×27
×24
×16
×11