Python Code Example: simple if-else statement

This simple code example illustrates the use of an if-else statement. It simply checks whether a given number is greater than or less than 5.

Code Explanation

1Initializes the variable a with the value 10
2 – 3If the value of the variable a is greater than 5, the string “a is greater than 5” is output
4 – 5If this is not the case, the string “a is smaller than 5” is output
a = 10

if a > 5:
    print("a is greater than 5")
    print("a is smaller than 5")
a is greater than 5