- The Python Apprentice
- Robert Smallshire Austin Bingham
- 83字
- 2021-07-02 22:16:55
if...else
The if-statement supports an optional else clause which goes in a block introduced by the else keyword (followed by a colon) which is indented to the same level as the if keyword. Let's start by creating (but not finishing) an if-block:
>>> h = 42
>>> if h > 50:
... print("Greater than 50")
To start the else block in this case, we just omit the indentation after the three dots:
... else:
... print("50 or smaller")
...
50 or smaller
推薦閱讀
- Django+Vue.js商城項(xiàng)目實(shí)戰(zhàn)
- Reactive Programming with Swift
- Learn Swift by Building Applications
- 從Java到Web程序設(shè)計(jì)教程
- SSM開發(fā)實(shí)戰(zhàn)教程(Spring+Spring MVC+MyBatis)
- Babylon.js Essentials
- ArcGIS for Desktop Cookbook
- C/C++代碼調(diào)試的藝術(shù)(第2版)
- Less Web Development Cookbook
- Extending Docker
- Python程序設(shè)計(jì)教程
- Hands-On Data Visualization with Bokeh
- Neo4j權(quán)威指南 (圖數(shù)據(jù)庫技術(shù)叢書)
- Go語言從入門到進(jìn)階實(shí)戰(zhàn)(視頻教學(xué)版)
- Python編程基礎(chǔ)