Python Less-than Operator
In Python, Comparison Less-than Operator takes two operands and returns a boolean value of True if the first operand is less than the second operand, else it returns True.
Syntax
The syntax to check if the value a
is less than the value b
using Less-than Operator is
</>
Copy
a < b
The above expression returns a boolean value.
Examples
1. Check if a number is less than other
In the following program, we take two numbers: a
, b
; and check if a
is less than b
.
main.py
</>
Copy
a = 2
b = 4
if a < b :
print('a is less than b.')
else :
print('a is not less than b.')
Output
a is less than b.
2. Check if a string is less than other
In the following program, we take two string values: a
, b
; and check if the string a
is less than the string b
lexicographically.
main.py
</>
Copy
a = 'mango'
b = 'banana'
if a < b :
print('a is less than b.')
else :
print('a is not less than b.')
Output
a is not less than b.
Conclusion
In this Python Tutorial, we learned about Comparison Less-than Operator, its syntax, and usage, with examples.