- 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.
推薦閱讀
- 精通Windows Vista必讀
- 返璞歸真:UNIX技術內幕
- OpenStack Cloud Computing Cookbook(Second Edition)
- 21天學通Java Web開發
- 大數據技術與應用
- Machine Learning with the Elastic Stack
- Working with Linux:Quick Hacks for the Command Line
- Mastering Exploratory Analysis with pandas
- 經典Java EE企業應用實戰
- Web編程基礎
- 人工智能:智能人機交互
- 30天學通Java Web項目案例開發
- PowerPoint 2010幻燈片制作高手速成
- Red Hat Enterprise Linux 5.0服務器構建與故障排除
- Getting Started with Tableau 2019.2