- 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
>>>
推薦閱讀
- Getting Started with ResearchKit
- SpringMVC+MyBatis快速開發與項目實戰
- Mastering Kotlin
- Hands-On JavaScript High Performance
- 秒懂設計模式
- Drupal 8 Configuration Management
- bbPress Complete
- 學習正則表達式
- SQL Server與JSP動態網站開發
- 微服務架構深度解析:原理、實踐與進階
- MongoDB,Express,Angular,and Node.js Fundamentals
- Visualforce Developer’s guide
- R用戶Python學習指南:數據科學方法
- Java并發編程之美
- Functional Python Programming