Python if..then Conditional Tutorial with Examples

Python provides the if..elif..else conditional in order to evaluate conditions and branching the program executions. The then keyword is not a python keyword but used in other programming languages. Simply the if..then is equal single if conditional in Python.

Single if Conditional or if..then

The single if conditional is equal to the if..then. So we will just check the given condition and if it is True we will execute the if code block. If it is False there will be nothing.

age = 20

if age>18:
   print("Over 18")

Nested if Conditional or Nested if..then

Also, the if or if..then conditional can be used as a nested form where multiple if or if..then will be chained together. In the following nested if..then the age and country will be checked in a nested way if age is over 18 and country is equal to "TR".

age = 20
country = "TR"

if age>18:
   if country == "TR":
      print("Over 18 From TR")

Leave a Comment