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

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
>>>
主站蜘蛛池模板: 长宁县| 亚东县| 三亚市| 武安市| 黑河市| 济阳县| 丹江口市| 宁国市| 铜山县| 海盐县| 池州市| 德江县| 田阳县| 松江区| 新河县| 巩留县| 鹤峰县| 崇文区| 洛宁县| 木里| 灵宝市| 三河市| 原阳县| 宁海县| 台北县| 沂源县| 柳林县| 修武县| 莱西市| 福州市| 竹溪县| 长武县| 红桥区| 浙江省| 兴安县| 卢龙县| 嘉荫县| 广饶县| 日喀则市| 任丘市| 怀安县|