Skip to content

Commit 1f06c90

Browse files
Add files via upload
1 parent 65ec9a0 commit 1f06c90

3 files changed

Lines changed: 144 additions & 0 deletions

File tree

week_3/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Python Operators
2+
3+
In Python, operators are special symbols that perform operations on values and variables. Here are the main types of operators and their definitions:
4+
5+
## Arithmetic Operators
6+
7+
Arithmetic operators are used to perform mathematical operations on numeric values.
8+
9+
- **`+`**: Addition - Adds two values.
10+
- **`-`**: Subtraction - Subtracts one value from another.
11+
- **`*`**: Multiplication - Multiplies two values.
12+
- **`/`**: Division - Divides one value by another.
13+
- **`%`**: Modulus - Returns the remainder of a division.
14+
- **`**`**: Exponentiation - Raises one value to the power of another.
15+
- **`//`**: Floor Division - Divides one value by another and rounds down to the nearest whole number.
16+
17+
## Assignment Operators
18+
19+
Assignment operators are used to assign values to variables. They also allow you to perform an operation and assign the result to the same variable.
20+
21+
- **`=`**: Assign - Assigns a value to a variable.
22+
- **`+=`**: Add and Assign - Adds a value to the variable and assigns the result to the variable.
23+
- **`-=`**: Subtract and Assign - Subtracts a value from the variable and assigns the result to the variable.
24+
- **`*=`**: Multiply and Assign - Multiplies the variable by a value and assigns the result to the variable.
25+
- **`/=`**: Divide and Assign - Divides the variable by a value and assigns the result to the variable.
26+
- **`%=`**: Modulus and Assign - Applies modulus operation and assigns the result to the variable.
27+
28+
## Comparison Operators
29+
30+
Comparison operators are used to compare two values and return a boolean result.
31+
32+
- **`==`**: Equal to - Returns `True` if two values are equal.
33+
- **`!=`**: Not equal to - Returns `True` if two values are not equal.
34+
- **`>`**: Greater than - Returns `True` if the left value is greater than the right value.
35+
- **`<`**: Less than - Returns `True` if the left value is less than the right value.
36+
- **`>=`**: Greater than or equal to - Returns `True` if the left value is greater than or equal to the right value.
37+
- **`<=`**: Less than or equal to - Returns `True` if the left value is less than or equal to the right value.
38+
39+
## Logical Operators
40+
41+
Logical operators are used to perform logical operations and combine boolean values.
42+
43+
- **`and`**: Logical AND - Returns `True` if both conditions are `True`.
44+
- **`or`**: Logical OR - Returns `True` if at least one condition is `True`.
45+
- **`not`**: Logical NOT - Returns `True` if the condition is `False`.
46+
47+
## Identity Operators
48+
49+
Identity operators are used to compare the memory location of two objects.
50+
51+
- **`is`**: Is - Returns `True` if two variables point to the same object in memory.
52+
- **`is not`**: Is not - Returns `True` if two variables do not point to the same object in memory.
53+
54+
## Membership Operators
55+
56+
Membership operators are used to test if a value is a member of a collection (like a list, tuple, or set).
57+
58+
- **`in`**: In - Returns `True` if a value is found in the collection.
59+
- **`not in`**: Not in - Returns `True` if a value is not found in the collection.
60+
61+
## Bitwise Operators
62+
63+
Bitwise operators perform operations on the binary representations of integers.
64+
65+
- **`&`**: Bitwise AND - Performs AND operation on each bit of two numbers.
66+
- **`|`**: Bitwise OR - Performs OR operation on each bit of two numbers.
67+
- **`^`**: Bitwise XOR - Performs XOR operation on each bit of two numbers.
68+
- **`~`**: Bitwise NOT - Inverts the bits of the number.
69+
- **`<<`**: Bitwise left shift - Shifts the bits of a number to the left by a specified number of positions.
70+
- **`>>`**: Bitwise right shift - Shifts the bits of a number to the right by a specified number of positions.
71+
72+
## Practice Questions and Resources
73+
74+
- **Practice Questions**: [HackerRank Python Practice](https://www.hackerrank.com/domains/tutorials/10-days-of-python)
75+
- **YouTube Channel**: [My Python Playlist](https://www.youtube.com/playlist?list=PLX1eV90xXed2wujMJKUdsWQu2UMS9ROGO)
76+
77+
Explore these resources to test your knowledge and enhance your programming skills!

week_3/fourth.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Arithmetic Operators
2+
a = 10
3+
b = 5
4+
print("Arithmetic Operators:")
5+
print("a + b =", a + b) # Addition
6+
print("a - b =", a - b) # Subtraction
7+
print("a * b =", a * b) # Multiplication
8+
print("a / b =", a / b) # Division
9+
print("a % b =", a % b) # Modulus
10+
print("a ** b =", a ** b) # Exponentiation
11+
print("a // b =", a // b) # Floor Division
12+
13+
# Assignment Operators
14+
x = 10
15+
x += 5 # x = x + 5
16+
print("\nAssignment Operators:")
17+
print("x += 5 -> x =", x)
18+
x -= 3 # x = x - 3
19+
print("x -= 3 -> x =", x)
20+
x *= 2 # x = x * 2
21+
print("x *= 2 -> x =", x)
22+
x /= 4 # x = x / 4
23+
print("x /= 4 -> x =", x)
24+
25+
# Comparison Operators
26+
y = 20
27+
z = 20
28+
print("\nComparison Operators:")
29+
print("y == z ->", y == z) # Equal to
30+
print("y != z ->", y != z) # Not equal to
31+
print("y > z ->", y > z) # Greater than
32+
print("y < z ->", y < z) # Less than
33+
print("y >= z ->", y >= z) # Greater than or equal to
34+
print("y <= z ->", y <= z) # Less than or equal to
35+
36+
# Logical Operators
37+
p = True
38+
q = False
39+
print("\nLogical Operators:")
40+
print("p and q ->", p and q) # Logical AND
41+
print("p or q ->", p or q) # Logical OR
42+
print("not p ->", not p) # Logical NOT
43+
44+
# Identity Operators
45+
a = [1, 2, 3]
46+
b = a
47+
c = [1, 2, 3]
48+
print("\nIdentity Operators:")
49+
print("a is b ->", a is b) # True because both refer to the same object
50+
print("a is not c ->", a is not c) # True because a and c refer to different objects
51+
52+
# Membership Operators
53+
list1 = [1, 2, 3, 4, 5]
54+
print("\nMembership Operators:")
55+
print("3 in list1 ->", 3 in list1) # True if 3 is in list1
56+
print("6 not in list1 ->", 6 not in list1) # True if 6 is not in list1
57+
58+
# Bitwise Operators
59+
m = 10 # Binary: 1010
60+
n = 4 # Binary: 0100
61+
print("\nBitwise Operators:")
62+
print("m & n =", m & n) # Bitwise AND
63+
print("m | n =", m | n) # Bitwise OR
64+
print("m ^ n =", m ^ n) # Bitwise XOR
65+
print("~m =", ~m) # Bitwise NOT
66+
print("m << 1 =", m << 1) # Bitwise left shift
67+
print("m >> 1 =", m >> 1) # Bitwise right shift

week_3/leacture 04.pptx

955 KB
Binary file not shown.

0 commit comments

Comments
 (0)