Control Flow: The if, elif, else Statements

Numeric Comparison

Similar to mathematical quantity comparison symbols, Python also has the respective operators for numeric comparison, however, the syntax is a little different in order to simplify coding with a regular general purpose keyboard. Note that the compound operators consisting of more than one symbol do not have spaces in between the symbols involved.

For the value “x = 10” and

Note that the = operator is the assignment operator and it cannot be used for comparison. One of the most common mistakes in coding is using = instead of == in comparison. The IDE platform may warn the programmer, however, when using remote tools or text editors on a remote server and without proper test coverage, the errors may go unnoticed until that code section is executed in the production system for the first time.

The result of the comparison expressions can be stored in a variable as a Boolean value of either True or False. Please try the following example with different values of x and y.

x = 3
y = 10

condition_variable = x >= y

print("The value of condition_variable is", condition_variable)

if (condition_variable):
    print("x is more than or equal to", y)
    
else:
    print("x is less than",y)