Table of Contents

, , , , , , , , ,

About the Club

Python Club Topics - Conditional statements

Conditional statements

  1. Determine 1 of multiple paths or which set of code to run depending on the evaluation of a condition
  2. if
  3. if/else
  4. if/elif/else

if example

  1. a = 100
    b = 200
     
    if b > a:
      print("b is greater than a")

if/else example

  1. a = 300
    b = 200
     
    if b > a:
      print("b is greater than a")
    else:
      print("a is greater than b")

if/elif/else example

  1. a = 200
    b = 200
     
    if b > a:
      print("b is greater than a")
    elif a == b:
      print("a and b are both equal")
    else:
      print("a is greater than b")