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

Info icon This 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:
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?
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 ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern