
Instruction of python operators
Defined Python operators
The operators are defined as symbols that can multiply the value of the operant. Here including values that an operator acts on are called operants. All operations are used to perform variables and values.
For the example of – 12 + 7 = 19, here ‘+’ sign is the operator, 12 and 7 that are called operands and output 19 is the operation.
print(12 + 7)
Output – 19
Key Points:-
- # Python operators basic
- Operation types of python
- Example of every types operators
Types of Python Operators
Operators work as a pillar of a program that is built-in separate code. Python provides the a variety of programs that including below –
- Arithmetic Operators
- Assignments Operators
- Comparison/ relational operators
- Logical Operators
- Membership Operators
- Identity Operators
- Bitwise Operators
Let’s go to see all the operators one by one.
Arithmetic operators
When we want to use mathematical operators including a python, here you need to add a numeric variable that is called Arithmetic operators. The basic thing of operations needs to be operated.
Arithmetic operators including points are additions (+), subtraction (-), multiplications (*), divide (/), reminder (%), exponent (**), floor division (//) operators.
Operators(Symbol) | Explanation | Example | Output |
Addition (+) | Add two operands | 12 + 7 | 19 |
Subtraction (-) | Right from left operands subtract | 12 – 7 | 5 |
Multiplication (*) | Multiples values either site | 12*7 | 84 |
Divide (/) | Divides left by the right operands | 7/12 | 1.7142 |
Reminder (%) | Divided left and right and right operands and return reminder | 12%7 | 5 |
Exponent (**) | Performed power calculation on operands | 12**7 (12 to the power 7) | 35831808 |
Assignments Operators
These operators are assigned two value operators. It is the various component operators in python
Operators (Symbol) | Explanation | Example |
= | Assign from right side to left side operends | A = 12 |
+=(add AND) | Add right to left operends and assign result left | A = a + 12 |
-= (add subtract) | Subtract Right to left operands and assign the result to left | A = a – 12 |
*= (Multiply add) | Multiply right to left operates and assign result left | A= a*12 |
/= (divide AND) | Divide left to right operand and assign result left | A = a/12 |
%= | Reminder right to left operends and assign values | A = a%12 |
**= (exponent AND) | Power calculations on operators values and assign result | A = a **12 |
//= (floor division) | Performs floor division and assign values | A = a//12 |
&= | Assign right and left operands and assign values | A = a&12 |
Comparison/ relational operators
Comparison/ relational operators compare the values of either site and show the result either TRUE and FALSE according to these two conditions. Basically, Comparison operators compare two values.
Example of comparison operators –
Operators | Explanation | Example |
== | When two operands are equal that value is true | a==b |
> | Getter than | a>b |
< | Less than | a<b |
!= | Not equal | a!=b |
>= | Getter than or equal to | a>=b |
<= | Less than or equal to | a<=b |
Logical Operators
These operators are used to combine conditional statements. Basically, these operators used to make a decision. Python supports three logical operators ‘and’, ‘or’, ’not’ operators.
For Example of logical operators –
a=man
s=woman
print( a and s is a and s)
The Output of these-
a and b is False
Operators | Explanation | Example |
AND | Return result TRUE when both statements are true | a<10 and a<20 |
OR | Return result TRUE when one of the statements is true | a<9 or a<8 |
NOT | Reverse the return result if FALSE then result is true | not(a<10 and a< 20) |
Membership Operators
These operators are used to test if a sequence was an object (like string, set, list, tuple, dictionary). There are two kinds of python membership operators ‘in’ and ‘not in’.
Example of python membership operators –
p= ‘Hello WigMarketing team’
q = {5:’x’, 6: ‘y’}
# output is True
print(‘H’ in p)
# output True
print(‘hello’ not in p)
# output: True
Print (5 in q)
Operators | Explanation | Example |
in | When the sequence value is an object detected the result of this operand is a TRUE object | a in b |
Not in | When the sequence value has not detected the operands that result showing True | a not in b |
Identity Operators
These operators compare the object not if operands are equal. Here all operands are the same object and same memory location but not equal. Including two variables are equal but not implied.
There are two kinds of python identity operators ‘is’ and ‘is not ’.
Example of the two operators –
A1 = 6
B1 = 6
Output : False
Print (a1 is not b1)
Operators | Explanation | Example |
is | When both operands are the same object then result True | a is b |
Is not | When both operands are not the same object or value then result True | a is not b |
Bitwise Operators
Normally, used these operators when I need to compare binary numbers. It works as bit-by-bit operations.
Example of the bitwise operator in python
If x = 8
y = 7
Then, 8(decimal)= 1000
And 7 (decimal) = 0111
Hence, x& y = 1111
Operators (meaning) | Explanation | Example |
& (AND) | All operands bit to 1 if both bits are 1 | 0000, 0000 |
| (OR) | Each bit to 1 if one of two bits is 1 | 0000, 1000 |
<< (LEFT SHIFT) | Binary left shift | 0010, 1000 |
>>(RIGHT SHIFT) | Binary right shift | 0000.0010 |
~ (NOT) | Inverts all bits | 1111, 0101 |
^ (XOR) | Each bit is 1 if only one bit to 1 | 0000, 1110 |
I think this article would be helpful, I believe in the quality of content. If there are any mistakes please let us know through the comment section. We are eagerly waiting to reply to you with a great update.