Book Image

Python Essentials

By : Steven F. Lott
Book Image

Python Essentials

By: Steven F. Lott

Overview of this book

Table of Contents (22 chapters)
Python Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Chapter 5. Logic, Comparisons, and Conditions

Our exploration of the Python language started with expression statements and the assignment statement. We can view output using the print() function as a simple statement. We can gather input using the input() function in an assignment statement. In order to process data conditionally, we need the if statement.

In order to look at the if statement, we'll need to look at Boolean data and Boolean operators. The and, or, not, and if-else Boolean operators have a "short-circuit" behavior: if the result is defined by just the left-hand operand, the right-hand side is not evaluated. This is an important feature of these logic operators. (The if-else operator is formally called the Boolean expression, but it behaves like the Boolean operators.)

We'll also look at the comparison operators. A comparison is a common way to create the Boolean values used to choose between suites of statements within an if statement.

We'll introduce the pass statement here...