- Python Tutorial
- Python variables and types
- Python Arithmetic Operators
- Python Lists – basics: define, access, assign, delete, print, concatenate
- Python Lists – Negative Indexing, Slicing, Stepping, Comparing, Max and Min
- Comparison Operators
- Assignment Operator
- Python membership and identity operators
- Python strings
- Python escape characters
- Python string special operators
- Built-in string operations in Python
- Built-in string operations in Python -II
- String Formatting Operators
- Special string operators
- Conditions in Python
- Loops in Python
- Functions in Python
- Python Classes, Objects and OOP concepts
- Class inheritance
- Generators
- Regular Expressions in Python
- Regular Expressions in Python – II
- Comprehension Lists in Python
- Python functions with multiple arguments
- Exception Handling in Python
- Sets in Python

Comparison operators are also known as relational operators. They are used to compare two values and return a Boolean ‘true’ or ‘false’ value.

‘==’ tries to establish whether two values are equal or not. If the two values are equal then in returns a ‘true’ else it will return ‘false’.

a = 5; b = 10; c = 5; print('a=5; b=10; c=5') if (a == b): print ('a is equal to b') else: print ('a is not equal to b') if (a==c): print ('a is equal to c') else: print ('a is not equal to c') if (b==c): print ('b is equal to c') else: print ('b is not equal to c')

Download the code Run the code

‘!=’ is the opposite of ‘==’ operator. Therefore, if the two values are not equal then in returns a ‘true’ else it will return ‘false’.

a = 5; b = 10; c = 5; print('a=5; b=10; c=5') if (a != b): print ('a is not equal to b') else: print ('a is equal to b') if (a != c): print ('a is not equal to c') else: print ('a is equal to c') if (b != c): print ('b is not equal to c') else: print ('b is equal to c')

Download the code Run the code

In mathematics ‘>’ symbol stands for greater than value and this is exactly what this operator tries to find out. If the value of the left operand is greater than the value of the right operand then it returns true else it will return false.

a = 5; b = 10; c = 5; print('a=5; b=10; c=5') if (a > b): print('a is greater than b') else: print('a is not greater than b') if (a > c): print('a is greater than c') else: print('a is not greater than c') if (b > c): print('b is greater than c') else: print('b is not greater than c')

Download the code Run the code

‘<’ symbol stands for less than value and this is exactly what this operator tries to find out. If the value of the left operand is less than the value of the right operand then it returns true else it will return false.

a = 5; b = 10; c = 5; print('a=5; b=10; c=5') if (a < b): print('a is less than b') else: print('a is not less than b') if (a < c): print('a is less than c') else: print('a is not less than c') if (b < c): print('b is less than c') else: print('b is not less than c')

Download the code Run the code

‘>=’ stands for greater than or equal to. If the operand on the left side is greater than or equal to the operand on the right it will return true or else it will return false

a = 5; b = 10; c = 5; print ('a=5; b=10; c=5') if (a >= b): print('a either greater or equal to b') else: print ('a is neither greater nor equal to b') if(a >= c): print ('a either greater or equal to c') else: print ('a is neither greater nor equal to c') if (b >= c): print ('b either greater or equal to c') else: print ('b is neither greater nor equal to c')

Download the code Run the code

‘<=’ stands for less than or equal to. If the operand on the left side is less than or equal to the operand on the right it will return true or else it will return false

a = 5; b = 10; c = 5; print('a=5; b=10; c=5') if (a <= b): print ('a either less than or equal to b') else: print ('a is neither less than nor equal to b') if (a <= c): print ('a either less than or equal to c') else: print ('a is neither less than nor equal to c') if (b <= c): print ('b either less than or equal to c') else: print ('b is neither less than nor equal to c')