Python if…else statements are used in decision making. The if statement evaluates a condition. If the condition is True, the statements within the if condition are executed. For example,
# Python if statement x = 5 if x < 10: print("x is less than 10")
The program will print the following output:
x is less than 10
However, if the condition within the if statement is evaluated to be False, then the statements within the else part are executed.
# Python if statement x = 11 if x < 10: print("x is less than 10") else: print("x is not less than 10")
The output will be:
x is not less than 10
Please note that Python requires the if statement to be properly indented. An if statement without proper indentation …






0 Comments