Skip to content

Commit 83de032

Browse files
committedAug 11, 2024
data structure has been added!
1 parent c695ae6 commit 83de032

File tree

8 files changed

+143
-0
lines changed

8 files changed

+143
-0
lines changed
 

Diff for: ‎02-control-flow/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Control Flow in Python
2+
3+
## Introduction
4+
5+
In this section, we will explore the control flow mechanisms in Python, including conditional statements and loops.
6+
7+
## 1. Condition
8+
In Python, we use `if`, `elif`, and `else` statements to implement conditional logic.
9+
10+
## 2. Control Flow
11+
Loops are used to execute a block of code repeatedly until a certain condition is met.

Diff for: ‎02-control-flow/conditions.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def check_number(num):
2+
"""Check if a number is positive, negative, or zero."""
3+
if num > 0:
4+
return "The number is positive."
5+
elif num < 0:
6+
return "The number is negative."
7+
else:
8+
return "The number is zero."
9+
number = 10
10+
print(f"Number: {number} - {check_number(number)}")
11+
12+
number = -5
13+
print(f"Number: {number} - {check_number(number)}")
14+
15+
number = 0
16+
print(f"Number: {number} - {check_number(number)}")

Diff for: ‎02-control-flow/loops.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fruits = ["apple", "banana", "cherry"]
2+
print("Fruits in the list:")
3+
for fruit in fruits:
4+
print(fruit)
5+
6+
count = 1
7+
print("\nCounting from 1 to 5:")
8+
while count <= 5:
9+
print(count)
10+
count += 1

Diff for: ‎03-data-structures/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
We will explore four fundamental data structures available in Python: lists, tuples, dictionaries, and sets. Understanding these data structures is essential for effective data management and manipulation in Python programming.
2+
3+
## 1. Lists
4+
5+
Lists are ordered collections that can hold multiple items of various types. They are mutable, meaning you can change their contents after they are created.
6+
7+
### Features
8+
- **Ordered**: Items have a defined order and maintain that order.
9+
- **Mutable**: You can add, remove, or modify items.
10+
- **Indexed**: Items are accessed by their index, starting from 0.
11+
12+
## 2. Tuples
13+
14+
Tuples are ordered collections similar to lists but are immutable, which means once they are created, their contents cannot be changed.
15+
16+
### Features
17+
- **Ordered**: Items have a defined order.
18+
- **Immutable**:We cannot add, modify, or remove items after creation.
19+
- **Indexed**: Items are accessed by their index, starting from 0.
20+
21+
## 3. Dictionaries
22+
23+
Dictionaries are unordered collections of key-value pairs. Each key is unique and is used to access the corresponding value.
24+
25+
### Features
26+
- **Unordered**: Items do not maintain a specific order.
27+
- **Mutable**: You can add, modify, or remove key-value pairs.
28+
- **Key-Value Pair**: Each item consists of a key and a corresponding value.
29+
30+
31+
## 4. Sets
32+
33+
Sets are unordered collections of unique elements. They are useful for operations such as membership testing, eliminating duplicates, and performing set operations.
34+
35+
### Features
36+
- **Unordered**: Items do not maintain any specific order.
37+
- **Mutable**: You can add or remove items, but items must be unique.
38+
- **Unique Elements**: Duplicate elements are automatically removed.

Diff for: ‎03-data-structures/dictionaries.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
person = {
3+
"name": "Alice",
4+
"age": 30,
5+
"city": "New York"
6+
}
7+
8+
print("Name:", person["name"])
9+
10+
person["email"] = "test@example.com"
11+
print("Dictionary after adding an email:", person)
12+
13+
del person["city"]
14+
print("Dictionary after removing city:", person)
15+
16+
print("Dictionary keys and values:")
17+
for key, value in person.items():
18+
print(f"{key}: {value}")
19+
20+
print("Email:", person.get("email", "Not found"))

Diff for: ‎03-data-structures/lists.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
fruits = ["apple", "banana", "cherry"]
2+
3+
print("First fruit:", fruits[0])
4+
5+
fruits.append("date")
6+
print("List after adding a fruit:", fruits)
7+
8+
fruits.remove("banana")
9+
print("List after removing a fruit:", fruits)
10+
11+
print("All fruits in the list:")
12+
for fruit in fruits:
13+
print(fruit)
14+
15+
16+
print("First two fruits:", fruits[:2])

Diff for: ‎03-data-structures/sets.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
numbers = {1, 2, 3, 4, 5}
3+
4+
numbers.add(6)
5+
print("Set after adding an element:", numbers)
6+
7+
numbers.remove(3)
8+
print("Set after removing an element:", numbers)
9+
10+
numbers.add(5)
11+
print("Set after adding a duplicate element:", numbers)
12+
13+
print("All numbers in the set:")
14+
for number in numbers:
15+
print(number)
16+
17+
set_a = {1, 2, 3}
18+
set_b = {3, 4, 5}
19+
20+
print("Union of sets:", set_a | set_b)
21+
print("Intersection of sets:", set_a & set_b)
22+
print("Difference of sets:", set_a - set_b)

Diff for: ‎03-data-structures/tuples.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
coordinates = (10, 20, 30)
2+
3+
print("First coordinate:", coordinates[0])
4+
5+
6+
print("All coordinates:")
7+
for coordinate in coordinates:
8+
print(coordinate)
9+
10+
print("First two coordinates:", coordinates[:2])

0 commit comments

Comments
 (0)
Please sign in to comment.