PYTHON OPERATORS
The operator can be defined as a symbol which is responsible for a particular operation
between two operands. Following are the types of Operators in Python.
• Arithmetic Operators
• Relational/ Comparison operator
• Assignment Operators
• Logical Operators
• Membership Operators
Arithmetic operators are used to perform arithmetic operations between two
operands.
• '+' operator can also be used to concatenate two strings on either side of the
operator.
>>> str1 = "Hello"
Class X COMPUTER SCIENCE Python Operators 1|Page
>>> str2 = "India"
>>> str1 + str2
'HelloIndia'
• '*' operator repeats the item on left side of the operator if first operand is a string
and second operand is an integer value.
>>> str1 = 'India'
>>> str1 * 2
'IndiaIndia'
Relational/ Comparison operator
Relational/ Comparison operators are used to comparing the value of the two
operands and returns Boolean true or false accordingly.
• Consider the given Python variables num1 = 10, num2 = 0, num3 = 10, str1 =
"Good", str2 = "Afternoon"
• Similarly, there are other relational operators like <= and >=.
Assignment Operators
Assignment operator assigns or changes the value of the variable on its left.
Class X COMPUTER SCIENCE Python Operators 2|Page
• Similarly, there are other assignment operators like --=, *=, /=, %=, //=, and
**=.
Logical Operators
There are three logical operators supported by Python. These operators (and, or ,not)
are to be written in lower case only. The logical operator evaluates to either True or
False based on the logical operands on its either side.
Membership Operators
Membership operator is used to check if a value is a member of the given
sequence or not.
Class X COMPUTER SCIENCE Python Operators 3|Page
Class X COMPUTER SCIENCE Python Operators 4|Page