- Daniel Arbuckle's Mastering Python
- Daniel Arbuckle
- 153字
- 2021-07-02 21:09:30
Flow control statements
Python has several flow control statements that will be familiar to people who know another language in the C family. For example, Python has loops and if, elif, and else branches (shown in the following code example):
selector = 5 if selector < 3: print("less than three") elif selector < 6: print("less than six") else: print("six or more") while selector > 0" print('selector is {}' .format(selector)) selector -=1 for x in ['a', 'b', 'c', 'd']: print(x) for x in range(5): print(x)
Python also has a for loop statement, but it's not like the for loops in C, C++, or Java. Instead of counting through numbers, the for loop iterates through the values. If we actually want to count through numbers with a for loop, that's easily done using a range iterator, as shown in the following screenshot in the output of the preceding code example:

Before we wrap-up this section, there's one last thing I should comment on and that's Python's views on indentation to signify the block structure.
推薦閱讀
- GraphQL學習指南
- ASP.NET Core 5.0開發入門與實戰
- Oracle從新手到高手
- iOS開發實戰:從零基礎到App Store上架
- Data Analysis with IBM SPSS Statistics
- Machine Learning in Java
- R用戶Python學習指南:數據科學方法
- Odoo 10 Implementation Cookbook
- PrimeFaces Blueprints
- 遠方:兩位持續創業者的點滴思考
- Visual C++開發寶典
- 從零開始構建深度前饋神經網絡:Python+TensorFlow 2.x
- 算法精解:C語言描述
- Java EE實用教程
- Effective C++:改善程序與設計的55個具體做法(第三版)中文版(雙色)