0 points

The else and elif Clauses


dashboard

Tue Apr 21 2020 12:00:59 GMT+0000 (UTC)

Posted by @RainbowBlooms #python #python #else #elif #clauses

   >>> x = 20 # x is a variable
  
  >>> if x < 50: # if condition
  ...    print('(first suite)')
  ...    print('x is small')
  ... else: else condition
  ...    print('(second suite)')
  ...    print('x is large')
  ...
 (first suite)
 x is small
                                
                                
content_copy Copy

In this example, x is less than 50, so the first suite (lines 4 to 5) are executed, and the second suite (lines 7 to 8) are skipped.