You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The operator can be defined as a symbol which is responsible
4
+
for a particular operation between two operands.
5
+
'''
6
+
#Arithmetic operators
7
+
'''
8
+
#Operator Description
9
+
+ (Addition) It is used to add two operands. For example, if a = 20, b = 10 => a+b = 30
10
+
- (Subtraction) It is used to subtract the second operand from the first operand. If the first operand is less than the second operand, the value results negative. For example, if a = 20, b = 10 => a - b = 10
11
+
/ (divide) It returns the quotient after dividing the first operand by the second operand. For example, if a = 20, b = 10 => a/b = 2.0
12
+
* (Multiplication) It is used to multiply one operand with the other. For example, if a = 20, b = 10 => a * b = 200
13
+
% (reminder) It returns the reminder after dividing the first operand by the second operand. For example, if a = 20, b = 10 => a%b = 0
14
+
** (Exponent) It is an exponent operator represented as it calculates the first operand power to the second operand.
15
+
// (Floor division) It gives the floor value of the quotient produced by dividing the two operands.
16
+
'''
17
+
# Comparison operators
18
+
'''
19
+
Operator Description
20
+
== If the value of two operands is equal, then the condition becomes true.
21
+
!= If the value of two operands is not equal, then the condition becomes true.
22
+
= If the first operand is less than or equal to the second operand, then the condition becomes true.
23
+
>= If the first operand is greater than or equal to the second operand, then the condition becomes true.
24
+
> If the first operand is greater than the second operand, then the condition becomes true.
25
+
< If the first operand is less than the second operand, then the condition becomes true.
26
+
'''
27
+
# Assignment Operators
28
+
'''
29
+
Operator Description
30
+
= It assigns the value of the right expression to the left operand.
31
+
+= It increases the value of the left operand by the value of the right operand and assigns the modified value back to left operand. For example, if a = 10, b = 20 => a+ = b will be equal to a = a+ b and therefore, a = 30.
32
+
-= It decreases the value of the left operand by the value of the right operand and assigns the modified value back to left operand. For example, if a = 20, b = 10 => a- = b will be equal to a = a- b and therefore, a = 10.
33
+
*= It multiplies the value of the left operand by the value of the right operand and assigns the modified value back to then the left operand. For example, if a = 10, b = 20 => a* = b will be equal to a = a* b and therefore, a = 200.
34
+
%= It divides the value of the left operand by the value of the right operand and assigns the reminder back to the left operand. For example, if a = 20, b = 10 => a % = b will be equal to a = a % b and therefore, a = 0.
35
+
*= a**=b will be equal to a=a**b, for example, if a = 4, b =2, a**=b will assign 4**2 = 16 to a.
36
+
//= A//=b will be equal to a = a// b, for example, if a = 4, b = 3, a//=b will assign 4//3 = 1 to a.
37
+
'''
38
+
# Logical Operators
39
+
'''
40
+
Operator Description
41
+
and If both the expression are true, then the condition will be true. If a and b are the two expressions, a → true, b → true => a and b → true.
42
+
or If one of the expressions is true, then the condition will be true. If a and b are the two expressions, a → true, b → false => a or b → true.
43
+
not If an expression a is true, then not (a) will be false and vice versa
44
+
'''
45
+
# Bitwise Operators
46
+
'''
47
+
Operator Description
48
+
& (binary and) If both the bits at the same place in two operands are 1, then 1 is copied to the result. Otherwise, 0 is copied.
49
+
| (binary or) The resulting bit will be 0 if both the bits are zero; otherwise, the resulting bit will be 1.
50
+
^ (binary xor) The resulting bit will be 1 if both the bits are different; otherwise, the resulting bit will be 0.
51
+
~ (negation) It calculates the negation of each bit of the operand, i.e., if the bit is 0, the resulting bit will be 1 and vice versa.
52
+
<< (left shift) The left operand value is moved left by the number of bits present in the right operand.
53
+
>> (right shift) The left operand is moved right by the number of bits present in the right operand.
54
+
'''
55
+
# Membership Operators
56
+
'''
57
+
Python membership operators are used to check
58
+
the membership of value inside a Python data structure.
59
+
If the value is present in the data structure,
60
+
then the resulting value is true otherwise it returns false.
61
+
Operator Description
62
+
in It is evaluated to be true if the first operand is found in the second operand (list, tuple, or dictionary).
63
+
not in It is evaluated to be true if the first operand is not found in the second operand (list, tuple, or dictionary).
64
+
'''
65
+
# Identity Operators
66
+
'''
67
+
The identity operators are used to decide whether an element certain class or type.
68
+
Operator Description
69
+
is It is evaluated to be true if the reference present at both sides point to the same object.
70
+
is not It is evaluated to be true if the reference present at both sides do not point to the same object.
71
+
'''
72
+
#Operator Precedence
73
+
'''
74
+
Operator Description
75
+
** The exponent operator is given priority over all the others used in the expression.
76
+
~ + - The negation, unary plus, and minus.
77
+
* / % // The multiplication, divide, modules, reminder, and floor division.
78
+
+ - Binary plus, and minus
79
+
>> << Left shift. and right shift
80
+
& Binary and.
81
+
^ | Binary xor, and or
82
+
<= < > >= Comparison operators (less than, less than equal to, greater than, greater then equal to).
0 commit comments