- Python Essentials
- Steven F. Lott
- 230字
- 2021-07-16 13:53:13
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. This statement does nothing. It's a place-holder to use when an empty suite of statements is all we need.
The assert
statement can be used to demonstrate that a particular logical condition is true at some point in the program's execution. This can clarify a potentially confusing algorithm. It can also serve as a handy debugging tool to make a program crash when something has gone awry.
- Python程序設計教程(第2版)
- Mastering AWS Lambda
- Fundamentals of Linux
- Learning C++ Functional Programming
- Effective Python Penetration Testing
- 響應式架構:消息模式Actor實現與Scala、Akka應用集成
- MySQL入門很輕松(微課超值版)
- Android傳感器開發與智能設備案例實戰
- Visual FoxPro 6.0程序設計
- Java Web應用開發給力起飛
- C++程序設計教程(第2版)
- 零基礎輕松學C++:青少年趣味編程(全彩版)
- Scratch編程從入門到精通
- Koa與Node.js開發實戰
- JavaScript Unit Testing