4. 更多控制流工具

As well as the while statement just introduced, Python uses a few more that we will encounter in this chapter.

4.1. if 语句

Perhaps the most well-known statement type is the if 语句。例如:

>>> x = int(input("Please enter an integer: "))
Please enter an integer: 42
>>> if x < 0:
...     x = 0
...     print('Negative changed to zero')
... elif x == 0:
...     print('Zero')
... elif x == 1:
...     print('Single')
... else:
...     print('More')
...
More