Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. Variables, Expression and...
  5. Operators and Types of Op...
  6. Comparison (Relational) Operators

Comparison (Relational) Operators

  • Comparison Operators are used to compare values
  • It either returns true or false depending on the condition
  • Assume a = 3 and b = 2

Example

a = 3
b = 2
print("a==b = ", a==b)
print("a!=b =",a!=b)
print("a>b =",a>b)
print("a<b =",a<b)
print("a>=b=",a>=b)
print("a<=b = ", a<=b)

Output

('a==b = ', False)
('a!=b =', True)
('a>b =', True)
('a<b =', False)
('a>=b=', True)
('a<=b = ', False)

Loading

Views: 3

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments