In Pytho1
In Pytho1
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)
1. Arithmetic Operators
Operat Exampl
Description
or e
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
// Floor Division x // y
Modulus
% x%y
(remainder)
Exponentiation
** x ** y
(power)
Examples:
python
Copy code
x = 10
y=3
print(x + y) # 13
print(x - y) # 7
print(x * y) # 30
print(x / y) # 3.3333333333333335
2. Assignment Operators
Operat Exampl
Description
or e
Assigns value to a
= x = 10
variable
Exponentiates and
**= x **= 3
assigns
Examples:
python
Copy code
x=5
x += 2 # x = x + 2 -> x becomes 7
x *= 3 # x = x * 3 -> x becomes 21
print(x) # Output: 21
3. Comparison Operators
These operators are used to compare two values. The result of a comparison
is always a boolean (True or False).
Operat Exampl
Description
or e
== Equal to x == y
!= Not equal to x != y
Greater than or
>= x >= y
equal to
Examples:
python
Copy code
x = 10
y=5
print(x == y) # False
print(x != y) # True
4. Logical Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
x = True
y = False
print(x or y) # True
print(not x) # False
5. Bitwise Operators
Operat
Description Example
or
Bitwise
` `
OR
Bitwise NOT
~ ~x
(inversion)
Examples:
python
Copy code
x = 5 # 101 in binary
y = 3 # 011 in binary
6. Membership Operators
Operat Exampl
Description
or e
Examples:
python
Copy code
lst = [1, 2, 3, 4]
7. Identity Operators
Identity operators are used to compare the memory locations of two objects.
Operat Exampl
Description
or e
Examples:
python
Copy code
x = [1, 2, 3]
y = [1, 2, 3]
z=x
python
Copy code
Example:
python
Copy code
x = 10
y = 20
print(max_value) # Output: 20
9. Operator Precedence
1. ** (Exponentiation)
2. ~, +, - (Unary operators)
4. +, - (Addition, Subtraction)
7. ^ (Bitwise XOR)
8. | (Bitwise OR)
Operator Overloading
Python allows you to change the behavior of its operators based on user-
defined data types by implementing special methods (also known as dunder
methods or magic methods).
python
Copy code
class Point:
self.x = x
self.y = y
def __str__(self):
p1 = Point(1, 2)
p2 = Point(3, 4)