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 Example

a = 10

if a > 5:
    print("a is greater than 5")
else:
    print("a is smaller than 5")
Output
a is greater than 5
Code Explanation

The code checks if the value of a is greater than 5. If it is, it prints “a is greater than 5”. If not, it prints “a is smaller than 5”. In this case, a is 10, so the code will print “a is greater than 5”.