-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path9th.py
41 lines (32 loc) · 831 Bytes
/
9th.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Lists
fruits = ["apple", "banana", "cherry"]
numbers = [1, 2, 3, 4, 5]
# Tuples
person = ("John", 30, "Male")
# Sets
colors = {"red", "green", "blue"}
# Dictionaries
person_info = {
"name": "John",
"age": 30,
"gender": "Male"
}
# Accessing elements
print(fruits[0]) # Output: "apple"
print(person[1]) # Output: 30
print(colors) # Output: {"red", "green", "blue"}
print(person_info["name"]) # Output: "John"
# Modifying elements
fruits[1] = "orange"
person = ("Jane", 25, "Female")
colors.add("yellow")
person_info["age"] = 35
# Iterating through collections
for fruit in fruits:
print(fruit)
for number in numbers:
print(number)
for color in colors:
print(color)
for key, value in person_info.items():
print(key, value)