- Hands-On Data Science and Python Machine Learning
- Frank Kane
- 194字
- 2021-07-15 17:15:03
The if-else loop
if 1 is 3:
print "How did that happen?"
elif 1 > 3:
print ("Yikes")
else:
print ("All is well with the world")
The output of the above code is as follows:
All is well with the world
We can also do if-else and else-if blocks here too. Let's do something a little bit more complicated here. If 1 is 3, I would print How did that happen? But of course 1 is not 3, so we will fall back down to the else-if block, otherwise, if 1 is not 3, we'll test if 1 > 3. Well that's not true either, but if it did, we print Yikes, and we will finally fall into this catch-all else clause that will print All is well with the world.
In fact, 1 is not 3, nor is 1 greater than 3, and sure enough, All is well with the world. So, you know, other languages have very similar syntax, but these are the peculiarities of Python and how to do an if-else or else-if block. So again, feel free to keep this notebook around. It might be a good reference later on.
- Getting Started with Gulp(Second Edition)
- WildFly:New Features
- 國(guó)際大學(xué)生程序設(shè)計(jì)競(jìng)賽中山大學(xué)內(nèi)部選拔真題解(二)
- 移動(dòng)UI設(shè)計(jì)(微課版)
- Objective-C應(yīng)用開(kāi)發(fā)全程實(shí)錄
- Oracle從新手到高手
- DevOps for Networking
- Mastering Swift 2
- PostgreSQL 11從入門到精通(視頻教學(xué)版)
- Access數(shù)據(jù)庫(kù)應(yīng)用教程(2010版)
- Modular Programming with JavaScript
- 從“1”開(kāi)始3D編程
- JavaScript Concurrency
- Spring Boot 3:入門與應(yīng)用實(shí)戰(zhàn)
- LabVIEW數(shù)據(jù)采集(第2版)