{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

python06.html - CHAPTER 6 Conditionals one of the most...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CHAPTER 6 Conditionals one of the most useful kinds of statements in a programming language: execute a piece of code depending on whether a condition is true or false flowchart syntax if <boolean expression>: <statements> if statement example x = 5 if x == 5: print( "x equals 5" ) x = 5 if x == 5: print( "x equals 5" ) in this example the "boolean" expression is x == 5 the expression evaluates to True if the value of x is 5, false otherwise x = 5 if x == 5: print( "x equals 5" ) in this example the "statements" is print( "x equals 5" ) the statements come after the ':' and are indented x = 5 if x == 5:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
print( "all these statements are executed if x equals 5" ) print( "x equals 5" ) print( "all of them" ) there can be many statements a boolean expression evaluates to either True or False True and False are the only boolean values in python True and False are of type bool In page 49 the book says: "...and anything that is not False, is True." it should really say: "... and anything that is not interpreted as False is interpreted as True." all the following are interpreted as false The special value False The special value None Every numerical value that is zero, e.g., 0 and 0.0 Every empty sequence, e.g., an empty string ("") Every empty "mapping," e.g., an empty dictionary anything else is True what does this print?
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}