Comparison and Logical Operators
Python Basics
Python Introduction
Python Installation
Overview of Jupyter IDE
Identifiers & Reserved Keywords
Python Variables
Python Numbers
Python Operators
Python Operators and Arithmetic Operators
Comparison and Logical Operators
Assignment and Bitwise Operators
Identity and Membership Operators
Python Flow Control
if else if else statement
While Loop Statement
Python For Loop
Break and Continue Statement
Python Data Types
Python Strings
Python Strings Methods
Python Lists
Python Tuples
Python Dictionary
Python Functions
Introduction to Python Functions
Function Arguments
Recursion Function
Lambda/Anonymous Function
Python - Modules
Python Files
Python - Files I/O
Python - Exceptions Handling
Python - Debugging
Comparison or Relational Operators
Comparison operators are used to compare values. It either returns True or False according to the condition.
# Sample code for Comparison Operators a = 20 b = 10 # Greater Than print('{} > {} is'.format(a,b),a>b) # Less Than print('{} < {} is'.format(a,b),a<b) # Equal To print('{} == {} is'.format(a,b),a==b) # Not Equal To print('{} != {} is'.format(a,b),a!=b) # Greater than or equal to print('{} >= {} is'.format(a,b),a>=b) # Less than or equal to print('{} <= {} is'.format(a,b),a<=b)
Output: 20 > 10 is True 20 < 10 is False 20 == 10 is False 20 != 10 is True 20 >= 10 is True 20 <= 10 is False
Logical Operators in Python
# Sample code for Logical Operators a = True b = False x = 50 y= 100 # 'and' Operator print('a and b is',a and b) print(x==y and x < y) # 'or' Operator print('a or b is',a or b) print(x==y or x < y) # 'not' Operator print('not a is',not a) print(not x==y) print(not x < y)
Output: a and b is False False ******************** a or b is True True ******************** not a is False True False