同步阅读进度,多语言翻译,过滤屏幕蓝光,评论分享,更多完整功能,更好读书体验,试试 阅读 ‧ 电子书库
Basic Examples
To demonstrate, let’s look at a few simple examples of the if statement at work. All parts are optional, except the initial if test and its associated statements. Thus, in the simplest case, the other parts are omitted:
>>> if 1:
... print('true')
...
true
Notice how the prompt changes to ... for continuation lines when typing interactively in the basic interface used here; in IDLE, you’ll simply drop down to an indented line instead (hit Backspace to back up). A blank line (which you can get by pressing Enter twice) terminates and runs the entire statement. Remember that 1 is Boolean true, so this statement’s test always succeeds. To handle a false result, code the else:
>>> if not 1:
... print('true')
... else:
... print('false')
...
false
请支持我们,让我们可以支付服务器费用。
使用微信支付打赏
