Skip to content

Commit 9a37ed1

Browse files
authored
Add files via upload
1 parent 5365089 commit 9a37ed1

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

Days-7-10.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
### **Day 7: Lists**
2+
Lists are versatile and commonly used data structures in Python.
3+
4+
- **List Basics:**
5+
- Lists are ordered collections of items.
6+
- They can contain elements of different data types.
7+
- **Accessing List Elements:**
8+
- You can access elements in a list by their index, starting from 0.
9+
- Example:
10+
11+
```python
12+
fruits = ["apple", "banana", "cherry"]
13+
print(fruits[0]) # Access the first item ("apple").
14+
print(fruits[1]) # Access the second item ("banana").
15+
```
16+
17+
- **List Methods:**
18+
- Lists have various built-in methods, such as `append()`, `insert()`, `remove()`, and `pop()`, to manipulate their contents.
19+
20+
### **Day 8: Tuples**
21+
Tuples are similar to lists, but they have unique characteristics.
22+
23+
- **Tuple Basics:**
24+
- Tuples are also ordered collections of elements.
25+
- They are immutable, meaning their contents cannot be changed after creation.
26+
- **Accessing Tuple Elements:**
27+
- You can access elements in a tuple using indexing, just like lists.
28+
- Example:
29+
30+
```python
31+
coordinates = (3, 4)
32+
print(coordinates[0]) # Access the first element (3).
33+
print(coordinates[1]) # Access the second element (4).
34+
```
35+
36+
- **Use Cases:**
37+
- Tuples are often used for collections of related values, such as coordinates or date and time components.
38+
39+
### **Day 9: Dictionaries**
40+
Dictionaries are powerful data structures for organizing data.
41+
42+
- **Dictionary Basics:**
43+
- Dictionaries consist of key-value pairs.
44+
- They are unordered, and keys must be unique.
45+
- **Accessing Dictionary Values:**
46+
- You can access values in a dictionary using their keys.
47+
- Example:
48+
49+
```python
50+
person = {
51+
"name": "Alice",
52+
"age": 25,
53+
"city": "New York"
54+
}
55+
print(person["name"]) # Access the value associated with the "name" key.
56+
print(person["age"]) # Access the value associated with the "age" key.
57+
```
58+
59+
- **Dictionary Methods:**
60+
- Dictionaries offer methods like `keys()`, `values()`, and `items()` to work with their keys and values.
61+
62+
### **Day 10: More on Data Structures**
63+
Learn advanced techniques for manipulating data structures.
64+
65+
- **List Manipulation:**
66+
- You can add, remove, and modify elements in lists.
67+
- Example:
68+
69+
```python
70+
fruits = ["apple", "banana", "cherry"]
71+
fruits.append("orange") # Add an element to the end of the list.
72+
fruits.remove("banana") # Remove a specific element from the list.
73+
fruits[0] = "kiwi" # Modify an element in the list.
74+
```
75+
76+
- **Dictionary Manipulation:**
77+
- Dictionaries can be extended, updated, and modified.
78+
- Example:
79+
80+
```python
81+
person = {"name": "Alice", "age": 25, "city": "New York"}
82+
person["country"] = "USA" # Add a new key-value pair to the dictionary.
83+
del person["city"] # Remove a key-value pair from the dictionary.
84+
person["age"] = 26 # Modify the value associated with the "age" key.
85+
```
86+
87+
Understanding and effectively using data structures like lists, tuples, and dictionaries is crucial in Python programming. Practice with these examples to gain confidence in managing and organizing data in your Python code.

0 commit comments

Comments
 (0)