- 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.
- C#程序設(shè)計(jì)實(shí)訓(xùn)指導(dǎo)書(shū)
- Android開(kāi)發(fā)精要
- Rake Task Management Essentials
- Android Application Development Cookbook(Second Edition)
- 零基礎(chǔ)學(xué)Python網(wǎng)絡(luò)爬蟲(chóng)案例實(shí)戰(zhàn)全流程詳解(入門(mén)與提高篇)
- Mastering Linux Security and Hardening
- Swift語(yǔ)言實(shí)戰(zhàn)晉級(jí)
- Machine Learning for OpenCV
- Visual Basic語(yǔ)言程序設(shè)計(jì)上機(jī)指導(dǎo)與練習(xí)(第3版)
- C語(yǔ)言程序設(shè)計(jì)教程
- 網(wǎng)絡(luò)綜合布線與組網(wǎng)實(shí)戰(zhàn)指南
- Java EE 7 Development with WildFly
- Mastering Node.js
- Mastering Unity Scripting
- Visual FoxPro數(shù)據(jù)庫(kù)程序設(shè)計(jì)