As we all know, the structure of program statement execution is nothing more than sequential structure, branch structure and loop structure. The same is true for Python. The sequential structure is too simple to mention. Let’s briefly record the similarities and differences between branches and loops and C++. By the way, for those who already know C++ For those who are learning Python, they should pay attention to the fact that statement blocks are controlled through indentation.
Branch structure: both use if and else, with an additional elif instead of C++'s else if. The essence is the same, so no examples are given
Loop structure: Compared with C++, there is no do..until statement, but while and for, which also uses break to end the loop and continue to enter the next loop, but there is a difference in for and a new statement pass. Examples are given below, but for the other parts, they are the same
for i in 'wyp': #Loop through the sequence structure
print 'This is', fruitfor i in range(3): #pass can’t do anything and feels useless
The above is about learning Python in anger - Chapter 1 Three articles - the content of structural control. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!