Python Greater-than Operator

In Python, Comparison Greater-than Operator takes two operands and returns a boolean value of True if the first operand is greater than the second operand, else it returns False.

Syntax

The syntax to check if the value a is greater than the value b using Greater-than Operator is

</>
Copy
a > b

The above expression returns a boolean value.

Examples

1. Check if a number is greater than other

In the following program, we take two numbers: a, b; and check if a is greater than b.

main.py

</>
Copy
a = 8
b = 4

if a > b :
    print('a is greater than b.')
else :
    print('a is not greater than b.')

Output

a is greater than b.

2. Check if a string is greater than other

In the following program, we take two string values: a, b; and check if the string a is greater that the string b lexicographically.

main.py

</>
Copy
a = 'apple'
b = 'banana'

if a > b :
    print('a is greater than b.')
else :
    print('a is not greater than b.')

Output

a is not greater than b.

Conclusion

In this Python Tutorial, we learned about Comparison Greater-than Operator, its syntax, and usage, with examples.