Operators in python
Operator are symbols that perform some actions or operations.
There are 7 types of operations in python:
1. Arithmetic operators
2. Comparison or relational operators
3. Logical operators
4. Assignment operators
5. Membership operators
6. Identity operators
7. Bitwise operators
Arithmetic operators are used to perform basic arithmetic operations. These are of 7 types in python:
I. Addition (+)
II. Subtraction (-)
III. Multiplication (*)
IV. Division (/)
V. Exponentiation (**)
VI. Modulus (%)
VII. Floor division (//)
Comparison operators are used to compare the two values on both side of the operators to produce logical/Boolean value True or False. There are 6 types of comparison operators in python:
I. Less than (<)
II. Greater than (>)
III. Less than or equal to (<=)
IV. Greater than or equal to (>=)
V. Equal to (==)
VI. Not equal to (!=)
Logical operators are used to combine conditional statements and the combined expression is called logical expression which always evaluate to logical/Boolean value True or False. Ther are 3 logical operators in python:
I. and
II. or
III. not
Assignment operators are used to assign a value to variable while performing some operation. There are 13 assignment operators in python:
I. =
II. +=
III. -=
IV. *=
V. /=
VI. %=
VII. //=
VIII. **=
IX. &=
X. |=
XI. ^=
XII. >>=
XIII. <<=
Membership operators are useful for test the membership of an object in a sequence such as string, list, tuple, dictionary and they result to either True or False. There are 2 membership operators in python:
I. in
II. not in
Identity operators are used to check if the two objects are same, with same memory allocation or not and results in either True or False. There are two identity operators in python:
I. is
II. is not
Bitwise operators are used to perform operations at binary digit level. Since these are performed at machine level in binary form, they are pretty fast. These are rarely used these common application. They are used special application where optimised use of memory is required. These are of 6 types in python:
I. &
II. |
III. ^
IV. ~
V. <<
VI. >>
Comments
Post a Comment