Operators in Python :
This is according the latest version of Python 3.7.
Operators are the constructs or signs which can manipulate and applied on the value of operands.
Consider the expression 2 * 3 = 6. Here, 2 and 3 are called operands and * is called operator.
Types of Operator :
Python language have following types of operators.
- Arithmetic Operators
- Comparison (Relational) Operators
- Assignment Operators
- Logical Operators
- Bit-wise Operators
- Membership Operators
- Identity Operators
Python Arithmetic Operators:
Arithmetic operators are used to perform arithmetic operations between two operands.
It includes +(addition), - (subtraction), *(multiplication), /(divide), %(reminder) and exponent (**).
Comparison operators are used for comparing the value of the two operands and returns
boolean value which is true or false accordingly.
boolean value which is true or false accordingly.
Python assignment operators:
The assignment operators are used to assign the value of the right side expression to the
For example : [X = 5] Here, X is on left side and 5 is on right side so it means we have
assigned 5 to X.
Python Bit-wise Operators:
Bit-wise operator works on bits and performs bit by bit operation.
For example the operation on a and b will be as follows :-
For example the operation on a and b will be as follows :-
Let a and b be:-
a = 0011 1100
b = 0000 1101
Python Logical Operators:
There are following logical operators supported by Python language. Assume variable
a = 10 and variable b = 20 then:
Membership Operators:
Python membership operators are used to check the membership of value inside a data. If the value is present in the data, then the resulting value is true otherwise it returns false.
Identity Operators:
Operator Precedence:
The precedence of the operators is important to find out since it enables us to know which operator should be evaluated first.
0 Comments