Python rookie tutorial learning 7: conditional loop statements

  • If conditional statement:if – elif – else
1 if condition_1:
2     statement_block_1
3 elif condition_2:
4     statement_block_2
5 else:
6     statement_block_3
  • While loop: you can useCTRL+CTo exit the infinite loop
While judgment condition:
    Execute statements
while :
  • For loop: use the break statement to jump out of the loop
for  in :
  • Range() function
    • Generate sequence:>>>for i in range(5)
    • Value of specified interval: range (5,9)
    • Start with the specified number and specify a different increment or step range (0, 10, 3)
    • You can combine the range () and Len () functions to traverse the index of a sequence
    • You can also use range() to create a list:>>>list(range(5))     [0, 1, 2, 3, 4]
  • Break and continue
    • Break is to jump out of the loop directly
    • Continue is to end this cycle to the next cycle
  • Pass statement: an empty statement to maintain the integrity of the program structure


Recommended Today

Vue2 technology finishing 3 – Advanced chapter – update completed

3. Advanced chapter preface Links to basic chapters: Link to component development: 3.1. Custom events of components 3.1.1. Binding custom events There are two implementation methods here: one is to use v-on with vuecomponent$ Emit implementation [PS: this method is a little similar to passing from child to parent]; The other is to use ref […]