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

Multiple lines

When we write multiple lines of code in the Python interpreter (for example, the If statement and for and while loop functions), then the interpreter uses three dots (...) as a secondary prompt for line continuation. To come out of these lines, you have to press the Enter key twice. Now we will look at the following example:

>>> val1 = 2500
>>> val2 = 2400
>>> if val1 > val2:
... print("val1 is greater than val2")
... else:
... print("val2 is greater than val1")
...
val1 is greater than val2
>>>

In this example, we've assigned integer values to two variables, val1 and val2, and we're checking whether val1 is greater than val2 or not. In this case, val1 is greater than val2, so the statement in the if block gets printed. Remember, statements in if and else blocks are indented. If you don't use indentation, you will get the following error:

>>> if val1 > val2:
... print("val1 is greater than val2")
File "<stdin>", line 2
print("val1 is greater than val2")
^
IndentationError: expected an indented block
>>>
主站蜘蛛池模板: 西盟| 马边| 尉犁县| 遂溪县| 贵州省| 巴彦淖尔市| 聊城市| 鄂尔多斯市| 福安市| 文化| 拉孜县| 长葛市| 外汇| 邹城市| 灌阳县| 泌阳县| 芜湖市| 乐山市| 宜兴市| 博乐市| 九江县| 大城县| 平乐县| 错那县| 贵德县| 瑞昌市| 潮州市| 阳泉市| 鸡泽县| 新津县| 黔南| 太仓市| 台前县| 嘉鱼县| 乐平市| 丹东市| 苗栗市| 星座| 莎车县| 邢台县| 麻阳|