Python Less-than or Equal-to Operator

In Python, Comparison Less-than or Equal-to Operator takes two operands and returns a boolean value of True if the first operand is less than or equal to the second operand, else it returns False.

Syntax

The syntax to check if the value a is less than or equal to the value b using Less-than or Equal-to Operator is

a <= b

The above expression returns a boolean value.

ADVERTISEMENT

Examples

1. Check if a number is less than or equal to other

In the following program, we take two numbers: a, b; and check if a is less than or equal to b.

main.py

a = 2
b = 4

if a <= b :
    print('a is less than or equal to b.')
else :
    print('a is not less than or equal to b.')
Try Online

Output

a is less than or equal to b.

2. Check if a string is less than or equal to other

In the following program, we take two string values: a, b; and check if the string a is less than or equal to the string b lexicographically.

main.py

a = 'apple'
b = 'banana'

if a <= b :
    print('a is less than or equal to b.')
else :
    print('a is not less than or equal to b.')
Try Online

Output

a is less than or equal to b.

Conclusion

In this Python Tutorial, we learned about Comparison Less-than or Equal-to Operator, its syntax, and usage, with examples.