Table of contents


Conditional statement

Expressions that used in if, elif statements must be estimated through True or False.

  1. Use simple if statement

     if <expression>:
         # statements
    

    For example:

     age = 10
     if age > 6:
         print("Junior")
    
  2. Use if..else statement

     if <expression>:
         # statements
     else:
         # other statements
    
  3. Use if .. elif .. else statement

     if <expression>:
         # statements
     elif <expression>:
         # statements
     elif <expression>:
         # statements
     else:
         # statements
    

Python does not have switch statement.


Loop statement

  1. while loop

     while <expression>:
         # statements
    

    For example:

     x = 0
     while x < 10:
         x = x + 1
    
     print('Current value: ' + str(x))
    
  2. For loop

     for <iter> in <somethings>:
         # statements
    

    For example:

     for letter in 'Hello, world':
         print(letter)
    


Wrapping up

  • Understanding about how to use the common statements in Python.

  • Use pass statement for empty function, class, loop or if .. else statements to avoid the error notifications from interpreter.