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

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
>>>
主站蜘蛛池模板: 根河市| 军事| 冷水江市| 关岭| 武陟县| 浦江县| 从化市| 平武县| 永昌县| 伊宁市| 苏尼特右旗| 曲松县| 徐州市| 揭阳市| 望城县| 兰州市| 隆林| 万源市| 昌江| 玉山县| 墨江| 涪陵区| 柳江县| 根河市| 阜阳市| 司法| 天镇县| 贺兰县| 房山区| 朔州市| 齐河县| 枣阳市| 敖汉旗| 巴彦淖尔市| 榆树市| 衡东县| 石嘴山市| 中江县| 吐鲁番市| 陇南市| 新沂市|