- Python Programming with Raspberry Pi
- Sai Yamanoor Srihari Yamanoor
- 93字
- 2021-07-02 23:48:47
An if-else statement
In the preceding example, we used an if statement to test each condition. In Python, there is an alternative option named the if-else statement. The if-else statement enables testing an alternative condition if the main condition is not true:
check_address = input("Is your address correct(yes/no)? ")
if check_address == "yes":
print("Thanks. Your address has been saved")
else:
del(address)
print("Your address has been deleted. Try again")
In this example, if the user input is yes, the indented code block under if is executed. Otherwise, the code block under else is executed.
推薦閱讀
- 腦動力:Linux指令速查效率手冊
- 大數據專業英語
- Python Artificial Intelligence Projects for Beginners
- 計算機原理
- 精通Excel VBA
- 西門子S7-200 SMART PLC實例指導學與用
- 計算機網絡技術基礎
- DevOps:Continuous Delivery,Integration,and Deployment with DevOps
- 系統安裝與重裝
- 新編計算機圖形學
- 過程控制系統
- Introduction to R for Business Intelligence
- Mastering Exploratory Analysis with pandas
- 設計模式
- 穿越計算機的迷霧