- 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.
- Linux C/C++服務器開發實踐
- iOS 9 Game Development Essentials
- Raspberry Pi Networking Cookbook(Second Edition)
- 算法精粹:經典計算機科學問題的Java實現
- Selenium Design Patterns and Best Practices
- Mastering Scientific Computing with R
- SQL Server 2016數據庫應用與開發習題解答與上機指導
- C# 8.0核心技術指南(原書第8版)
- Python機器學習算法: 原理、實現與案例
- Spring 5 Design Patterns
- C++17 By Example
- Elasticsearch搜索引擎構建入門與實戰
- Mastering Python
- Python人工智能項目實戰
- 新手學ASP.NET 3.5網絡開發