© Irv Kalb 2016

Irv Kalb, Learn to Program with Python, 10.1007/978-1-4842-2172-3_5

5. if, else, and elif Statements

Irv Kalb

(1)Mountain View, California, USA

All the code that we have looked at so far has essentially been linear. That is, execution of the code starts from the top and goes straight through to the bottom. The only change to this linear nature of execution is when we make a function call. This transfers control to the function, but all the code inside a function also goes straight through from top to bottom. But one of the most powerful things about code is the ability to make a decision and to take a path based on that decision.

This chapter discusses the following topics:

  • Flowcharting

  • The if statement

  • Comparison operators

  • Examples ...

Get Learn to Program with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.