Skip to content

Commit d0b806f

Browse files
create files for day-6
Signed-off-by: Abhishek Veeramalla <[email protected]>
1 parent 0986fee commit d0b806f

15 files changed

+373
-0
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Arithmetic Operations in Python
2+
3+
## Introduction
4+
5+
Arithmetic operators in Python allow you to perform basic mathematical calculations on numeric values. These operators include addition, subtraction, multiplication, division, and more.
6+
7+
## List of Arithmetic Operators
8+
9+
1. **Addition (+):** Adds two numbers.
10+
2. **Subtraction (-):** Subtracts the right operand from the left operand.
11+
3. **Multiplication (*):** Multiplies two numbers.
12+
4. **Division (/):** Divides the left operand by the right operand (results in a floating-point number).
13+
5. **Floor Division (//):** Divides the left operand by the right operand and rounds down to the nearest whole number.
14+
6. **Modulus (%):** Returns the remainder of the division of the left operand by the right operand.
15+
7. **Exponentiation (**):** Raises the left operand to the power of the right operand.
16+
17+
## Examples
18+
19+
### Addition
20+
21+
```python
22+
a = 5
23+
b = 3
24+
result = a + b
25+
print(result) # Output: 8
26+
```
27+
28+
### Subtraction
29+
30+
```python
31+
x = 10
32+
y = 7
33+
result = x - y
34+
print(result) # Output: 3
35+
```
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Assignment Operations in Python
2+
3+
## Introduction
4+
5+
Assignment operators in Python are used to assign values to variables. They include the basic assignment operator (=) and various compound assignment operators that perform an operation on the variable while assigning a value.
6+
7+
## List of Assignment Operators
8+
9+
1. **Basic Assignment (=):** Assigns a value to a variable.
10+
11+
2. **Addition Assignment (+=):** Adds the right operand to the left operand and assigns the result to the left operand.
12+
13+
3. **Subtraction Assignment (-=):** Subtracts the right operand from the left operand and assigns the result to the left operand.
14+
15+
4. **Multiplication Assignment (*=):** Multiplies the left operand by the right operand and assigns the result to the left operand.
16+
17+
5. **Division Assignment (/=):** Divides the left operand by the right operand and assigns the result to the left operand.
18+
19+
6. **Floor Division Assignment (//=):** Performs floor division on the left operand and assigns the result to the left operand.
20+
21+
7. **Modulus Assignment (%=):** Calculates the modulus of the left operand and assigns the result to the left operand.
22+
23+
8. **Exponentiation Assignment (**=):** Raises the left operand to the power of the right operand and assigns the result to the left operand.
24+
25+
## Examples
26+
27+
### Basic Assignment
28+
29+
```python
30+
x = 5
31+
```
32+
33+
### Addition Assignment
34+
35+
```python
36+
y = 10
37+
y += 3 # Equivalent to y = y + 3
38+
```

Day-06/01-Notes/Bitwise Operators.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Bitwise Operations in Python
2+
3+
## Introduction
4+
5+
Bitwise operators in Python are used to perform operations on individual bits of binary numbers. These operators include bitwise AND, OR, XOR, and more.
6+
7+
## List of Bitwise Operators
8+
9+
1. **Bitwise AND (&):** Performs a bitwise AND operation on the binary representations of the operands.
10+
2. **Bitwise OR (|):** Performs a bitwise OR operation.
11+
3. **Bitwise XOR (^):** Performs a bitwise XOR operation.
12+
4. **Bitwise NOT (~):** Flips the bits of the operand, changing 0 to 1 and 1 to 0.
13+
5. **Left Shift (<<):** Shifts the bits to the left by a specified number of positions.
14+
6. **Right Shift (>>):** Shifts the bits to the right.
15+
16+
## Examples
17+
18+
### Bitwise AND
19+
20+
```python
21+
a = 5 # Binary: 0101
22+
b = 3 # Binary: 0011
23+
result = a & b # Result: 0001 (Decimal: 1)
24+
```
25+
26+
### Bitwise OR
27+
28+
```python
29+
x = 10 # Binary: 1010
30+
y = 7 # Binary: 0111
31+
result = x | y # Result: 1111 (Decimal: 15)
32+
```

Day-06/01-Notes/Identity Operators.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Identity Operations in Python
2+
3+
## Introduction
4+
5+
Identity operators in Python are used to compare the memory locations of two objects to determine if they are the same object or not. The two identity operators are "is" and "is not."
6+
7+
## List of Identity Operators
8+
9+
1. **is:** Returns `True` if both operands refer to the same object.
10+
2. **is not:** Returns `True` if both operands refer to different objects.
11+
12+
### Examples
13+
14+
#### is Operator
15+
16+
```python
17+
x = [1, 2, 3]
18+
y = x # y now refers to the same object as x
19+
result = x is y
20+
# result will be True
21+
```
22+
23+
#### is not Operator
24+
25+
```python
26+
a = "hello"
27+
b = "world"
28+
result = a is not b
29+
# result will be True
30+
```

Day-06/01-Notes/Logical Operators.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Logical Operations in Python
2+
3+
## Introduction
4+
5+
Logical operators in Python are used to manipulate and combine Boolean values. These operators allow you to perform logical operations such as AND, OR, and NOT.
6+
7+
## List of Logical Operators
8+
9+
1. **AND (and):** Returns `True` if both operands are `True`.
10+
2. **OR (or):** Returns `True` if at least one of the operands is `True`.
11+
3. **NOT (not):** Returns the opposite Boolean value of the operand.
12+
13+
## Examples
14+
15+
### AND Operator
16+
17+
```python
18+
x = True
19+
y = False
20+
result = x and y
21+
# result will be False
22+
```
23+
24+
### OR Operator
25+
26+
```python
27+
a = True
28+
b = False
29+
result = a or b
30+
# result will be True
31+
```
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Membership Operations in Python
2+
3+
## Introduction
4+
5+
Membership operators in Python are used to check whether a value is present in a sequence or collection, such as a list, tuple, or string. The membership operators are "in" and "not in."
6+
7+
## List of Membership Operators
8+
9+
1. **in:** Returns `True` if the left operand is found in the sequence on the right.
10+
2. **not in:** Returns `True` if the left operand is not found in the sequence on the right.
11+
12+
### Examples
13+
14+
#### in Operator
15+
16+
```python
17+
fruits = ["apple", "banana", "cherry"]
18+
result = "banana" in fruits
19+
# result will be True
20+
```
21+
22+
#### not in Operator
23+
24+
```python
25+
colors = ["red", "green", "blue"]
26+
result = "yellow" not in colors
27+
# result will be True
28+
```
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Precedence of Operations in Python
2+
3+
## Introduction
4+
5+
Precedence of operations in Python defines the order in which different types of operators are evaluated in an expression. Operators with higher precedence are evaluated first.
6+
7+
## Examples
8+
9+
### Arithmetic Precedence
10+
11+
```python
12+
result = 5 + 3 * 2
13+
# Multiplication has higher precedence, so result is 11, not 16
14+
```
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Relational Operations in Python
2+
3+
## Introduction
4+
5+
Relational operators in Python are used to compare two values and determine the relationship between them. These operators return a Boolean result, which is either `True` or `False`.
6+
7+
## List of Relational Operators
8+
9+
1. **Equal to (==):** Checks if two values are equal.
10+
11+
2. **Not equal to (!=):** Checks if two values are not equal.
12+
13+
3. **Greater than (>):** Checks if the left operand is greater than the right operand.
14+
15+
4. **Less than (<):** Checks if the left operand is less than the right operand.
16+
17+
5. **Greater than or equal to (>=):** Checks if the left operand is greater than or equal to the right operand.
18+
19+
6. **Less than or equal to (<=):** Checks if the left operand is less than or equal to the right operand.
20+
21+
## Examples
22+
23+
### Equal to
24+
25+
```python
26+
a = 5
27+
b = 5
28+
result = a == b
29+
# result will be True
30+
```
31+
32+
### Not equal to
33+
34+
```python
35+
x = 10
36+
y = 7
37+
result = x != y
38+
# result will be True
39+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
a = 10
2+
b = 5
3+
4+
sum_result = a + b
5+
difference_result = a - b
6+
product_result = a * b
7+
quotient_result = a / b
8+
9+
print("Sum:", sum_result)
10+
print("Difference:", difference_result)
11+
print("Product:", product_result)
12+
print("Quotient:", quotient_result)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
a = 10
2+
b = 5
3+
4+
less_than = a < b
5+
greater_than = a > b
6+
less_than_or_equal = a <= b
7+
greater_than_or_equal = a >= b
8+
equal = a == b
9+
not_equal = a != b
10+
11+
print("a < b:", less_than)
12+
print("a > b:", greater_than)
13+
print("a <= b:", less_than_or_equal)
14+
print("a >= b:", greater_than_or_equal)
15+
print("a == b:", equal)
16+
print("a != b:", not_equal)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
x = True
2+
y = False
3+
4+
and_result = x and y
5+
or_result = x or y
6+
not_result_x = not x
7+
not_result_y = not y
8+
9+
print("x and y:", and_result)
10+
print("x or y:", or_result)
11+
print("not x:", not_result_x)
12+
print("not y:", not_result_y)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
total = 10
2+
3+
total += 5
4+
total -= 3
5+
total *= 2
6+
total /= 4
7+
8+
print("Final total:", total)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
my_list = [1, 2, 3, 4, 5]
2+
3+
# Identity operators
4+
a = my_list
5+
b = [1, 2, 3, 4, 5]
6+
7+
is_same_object = a is my_list
8+
is_not_same_object = b is not my_list
9+
10+
# Membership operators
11+
element_in_list = 3 in my_list
12+
element_not_in_list = 6 not in my_list
13+
14+
print("a is my_list:", is_same_object)
15+
print("b is not my_list:", is_not_same_object)
16+
print("3 in my_list:", element_in_list)
17+
print("6 not in my_list:", element_not_in_list)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# Python Operators Assignment
3+
4+
In this assignment, you will explore various Python operators and their usage. Please complete the following tasks.
5+
6+
## Task 1: Arithmetic Operators
7+
8+
1. Create two variables `a` and `b` with numeric values.
9+
2. Calculate the sum, difference, product, and quotient of `a` and `b`.
10+
3. Print the results.
11+
12+
## Task 2: Comparison Operators
13+
14+
1. Compare the values of `a` and `b` using the following comparison operators: `<`, `>`, `<=`, `>=`, `==`, and `!=`.
15+
2. Print the results of each comparison.
16+
17+
## Task 3: Logical Operators
18+
19+
1. Create two boolean variables, `x` and `y`.
20+
2. Use logical operators (`and`, `or`, `not`) to perform various logical operations on `x` and `y`.
21+
3. Print the results.
22+
23+
## Task 4: Assignment Operators
24+
25+
1. Create a variable `total` and initialize it to 10.
26+
2. Use assignment operators (`+=`, `-=`, `*=`, `/=`) to update the value of `total`.
27+
3. Print the final value of `total`.
28+
29+
## Task 5: Bitwise Operators (Optional)
30+
31+
1. If you are comfortable with bitwise operators, perform some bitwise operations on integer values and print the results. If not, you can skip this task.
32+
33+
## Task 6: Identity and Membership Operators
34+
35+
1. Create a list `my_list` containing a few elements.
36+
2. Use identity operators (`is` and `is not`) to check if two variables are the same object.
37+
3. Use membership operators (`in` and `not in`) to check if an element is present in `my_list`.
38+
4. Print the results.
39+
40+

Day-06/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Introduction to Operators in Python
2+
3+
Operators in Python are special symbols or keywords that are used to perform operations on variables and values. Python supports a wide range of operators, categorized into several types. These operators allow you to perform tasks such as arithmetic calculations, assign values to variables, compare values, perform logical operations, and more.
4+
5+
Here are the main types of operators in Python:
6+
7+
1. **Arithmetic Operators:** These operators are used for performing basic mathematical operations such as addition, subtraction, multiplication, division, and more.
8+
9+
2. **Assignment Operators:** Assignment operators are used to assign values to variables. They include the equal sign (=) and various compound assignment operators.
10+
11+
3. **Relational Operators:** Relational operators are used to compare values and determine the relationship between them. They return a Boolean result (True or False).
12+
13+
4. **Logical Operators:** Logical operators are used to combine and manipulate Boolean values. They include "and," "or," and "not."
14+
15+
5. **Identity Operators:** Identity operators are used to check if two variables point to the same object in memory. The identity operators in Python are "is" and "is not."
16+
17+
6. **Membership Operators:** Membership operators are used to check if a value is present in a sequence or collection, such as a list, tuple, or string. The membership operators in Python are "in" and "not in."
18+
19+
7. **Bitwise Operators:** Bitwise operators are used to perform operations on individual bits of binary numbers. They include bitwise AND, OR, XOR, and more.
20+
21+
8. **Precedence of Operations:** Operators in Python have different levels of precedence, which determine the order in which operations are performed in an expression.

0 commit comments

Comments
 (0)