What else is there in Python?
[size=10.5pt]We all use the else keyword in Python,usually accompanying if statement:
CODE:
if x > 0:print 'positive'
elif x < 0:
print 'negative'
else:
print 'zero' [size=10.5pt]but Python has a few other uses to the else keyword that mostpeople are unfamiliar with.
for .. else
I bet you didn’t know that you can put an else clause after a for loop! What does it do? When the items you iterator over are exhausted, the else clause is executed. When aren’t the items exhausted? When you use a break statement.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-736618/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- what is the Mixin method in Python?Python
- python中for……else……的使用Python
- python 中的 for-else 和 while-else 語句PythonWhile
- What---Python演算法Python演算法
- python中的while...elsePythonWhile
- Python if else條件語句Python
- Python中if else語句出錯Python
- Python 基礎 - if else流程判斷Python
- Python if else條件語句詳解Python
- JS - if else and else if statementJS
- Python 中的for,if-else和while語句PythonWhile
- if-else if-else 的用法
- python 利用 for ... else 跳出雙層巢狀迴圈Python巢狀
- Python的if else 巢狀 和forin while 迴圈Python巢狀While
- What is wrong?
- what is life?
- What is WebpackWeb
- What is maven?Maven
- What is Babel?Babel
- Python異常處理 try、except和else的使用Python
- if if和if else if
- What is a service mesh?
- What is rate limiting?MIT
- WHAT IS PPM Encoder ?
- What is an SQL relation?SQL
- 笨辦法學C 練習12:If,Else If,Else
- [Information Security] What is WEPORM
- What are the benefits of using an proxy?
- What is dbo in SQL Server?SQLServer
- CISO之What & How
- What is the "WF - Contention'' Enqueue ?ENQ
- What does -> do in clojure?
- python中if語句的用法及if-else結構的使用Python
- if、else if、else判斷語句的幾個小例子
- 多型消除if else多型
- if else與策略模式模式
- JavaScript if else 語句JavaScript
- What is the difference between a Homemaker and a Housewife?
- What does "xargs grep" do?