operators are used for manipulating given values with the help of operands.
For example,
1+2
Here, 1 and 2 are considered as operands and + is operator.There are various types of operators in python:
->Arithmetic operators
->Comparison (Relational) operators
->Logical (Boolean) operators
->Bitwise operators
->Assignment operators
->Special operators
Arithmetic operators:
Most of the mathematical expressions are evaluated with the help of arithmetic operators. Here is the list of various arithmetic operators:
OPERATOR | NAME | DESCRIPTION |
---|---|---|
+ | Addition | Adds the values of operands |
- | Subtraction | Subtracts operand valus from right to left |
* | Multiplication | Multiplies values of given operands |
/ | Division | Divides the values of operand |
% | Modulus | Divides the values of operand and returns remainder |
** | Exponent | Exponential(power) calculation of operator is done |
// | Floor division | Result of division will be rounded. |
Comparison operators:
comparing of values between operand can be done with the help of comparison operators.They are also called as reltional operators since the type of relationship is found between values during comparison.
some of the relational operators are shown in the given table:
OPERATOR | NAME | DESCRIPTION |
---|---|---|
> | Greater that | Checks which operand value is greater |
< | Less that | Checks which operand value is lesser |
== | Equal to | When both operand values are equal then condition is true |
!= | Not equal to | When both operand values are not equal then condition is true |
>= | Greater than or equal to | When left operand value is greater than or equal to right operand the the condition become true |
<= | Less than or equal to | When left operand value is less than or equal to right operand the the condition becomes true |
Logical operators:
Logical operators are also referred to as boolean operators.Some of the logical operators which are used in python are shown below:
NAME | DESCRIPTION |
---|---|
and | when both operands are true then it is true |
or | when one of the operands are true then it is true |
not | It is the reverse of given operand's logical state |
Bitwise operators:
The operator which is used to perform bit by bit operation are called as bitwise operators. Some of the bitwise operators are listed in the below tabe:
OPERATOR | NAME |
---|---|
& | Bitwise AND |
| | Bitwise OR |
~ | Bitwise NOT |
^ | Bitwise XOR |
>> | Bitwise right shift |
<< | Bitwise left shift |
Assignment operators:
Assigning values to variables can be done with the help of assignment operators. Various assignment operators are listed below:
NAME | EXAMPLE | EQUIVALENT |
---|---|---|
= | a = 2 | a = 2 |
+= | a += 2 | a = a + 2 |
-= | a -= 2 | a = a - 2 |
*= | a *= 2 | a = a * 2 |
/= | a /= 2 | a = a / 2 |
%= | a %= 2 | a = a % 2 |
//= | a //= 2 | a = a // 2 |
**= | a **= 2 | a = a ** 2 |
&= | a &= 2 | a = a & 2 |
|= | a |= 2 | a = a | 2 |
^= | a ^= 2 | a = a ^ 2 |
>>= | a >>= 2 | a = a >> 2 |
<<= | a <<= 2 | a = a << 2 |
Special operators:
Python provides some types of special operators.They are,
->Identity operators
->Membership operators
Identity operators:
Python uses identity operators to compare the memory location between two variables or objects. Some of the identity operators are listed below:
NAME | DESCRIPTION |
---|---|
is | Checks whether the given two operands are same or identical |
is not | It is true when given two operands are not same or not identical |
Membership operators:
It checks for membershipship in a given sequence like strings,list,dictionary. Some of the membership operators are shown below:
NAME | DESCRIPTION |
---|---|
in | Varaible or value is found in the sequence then it is true |
not in | Varaible or value is not found in the sequence then it is true |
Advertisement Powered By Google Adsense
python python tutorial learn python learning python python code learning java python language python documentation python tutor python basics python download python online python for dummies how to learn python