官术网_书友最值得收藏!

  • 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.

主站蜘蛛池模板: 陆川县| 邵东县| 贞丰县| 新蔡县| 周口市| 古浪县| 迁安市| 榆社县| 丹巴县| 清河县| 玉门市| 兰考县| 洪洞县| 伽师县| 三都| 民勤县| 北川| 英德市| 博兴县| 章丘市| 苏尼特右旗| 寿宁县| 清原| 汨罗市| 尚志市| 武威市| 高要市| 塘沽区| 荆门市| 雷山县| 延庆县| 新竹市| 涟水县| 西华县| 洞头县| 海安县| 庆城县| 中江县| 墨竹工卡县| 彩票| 同江市|