- 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.
推薦閱讀
- Visual Basic程序設(shè)計(jì)教程
- Learning C++ Functional Programming
- Flux Architecture
- PostgreSQL Replication(Second Edition)
- 深入淺出PostgreSQL
- Visual Basic程序設(shè)計(jì)上機(jī)實(shí)驗(yàn)教程
- 零代碼實(shí)戰(zhàn):企業(yè)級(jí)應(yīng)用搭建與案例詳解
- Learning JavaScript Data Structures and Algorithms(Second Edition)
- OpenCV 3計(jì)算機(jī)視覺(jué):Python語(yǔ)言實(shí)現(xiàn)(原書(shū)第2版)
- STM8實(shí)戰(zhàn)
- 產(chǎn)品架構(gòu)評(píng)估原理與方法
- Flutter從0基礎(chǔ)到App上線
- 軟件再工程:優(yōu)化現(xiàn)有軟件系統(tǒng)的方法與最佳實(shí)踐
- Building E-Commerce Solutions with WooCommerce(Second Edition)
- 跟著迪哥學(xué)Python數(shù)據(jù)分析與機(jī)器學(xué)習(xí)實(shí)戰(zhàn)