- Mastering Python Scripting for System Administrators
- Ganesh Sanjiv Naik
- 186字
- 2021-07-02 14:00:18
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
>>>
推薦閱讀
- Boost.Asio C++ Network Programming(Second Edition)
- Java面向對象軟件開發
- 造個小程序:與微信一起干件正經事兒
- Leap Motion Development Essentials
- C和C++安全編碼(原書第2版)
- PyTorch Artificial Intelligence Fundamentals
- 算法訓練營:提高篇(全彩版)
- bbPress Complete
- Spring Boot進階:原理、實戰與面試題分析
- 劍指大數據:企業級數據倉庫項目實戰(在線教育版)
- 編程菜鳥學Python數據分析
- QGIS Python Programming Cookbook(Second Edition)
- .NET 4.5 Parallel Extensions Cookbook
- 計算機應用基礎(第二版)
- Google Maps JavaScript API Cookbook