-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter_05.py
More file actions
112 lines (68 loc) · 2.14 KB
/
chapter_05.py
File metadata and controls
112 lines (68 loc) · 2.14 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# age = 20
# ishfaq_student_Marks = 10.5,20,25,18,NaN
# ======= > List < =========
# fruits = ["apple", "mango", "banana"]
# print(fruits[-1])
# fruits[1] = "orange"
# print(fruits)
# fruits.append("grape") #add at end
# print(fruits)
# fruits.insert(1, "kiwi") # add at positoin 1
# print(fruits)
# fruits.remove("apple") # remove value in the list
# print(fruits)
# fruits.pop() # remove last item
# print(fruits)
# print(len(fruits)) # check the no of values in the list
# ======== > List comprehension < ==========
# squares = [ x*x for x in range(20)]
# print(squares)
# even_numbers = [x for x in range(100) if x % 2 == 0]
# print(even_numbers)
# ========== > Tuples < ==============
# colors = ("red", "green", "blue")
# print(colors[1])
# # colors[0] = "orange"
# # print(colors)
# Student_data = ("Ishfaq", 20, "Pakistan")
# name, age, country = Student_data
# print(f"Name: {name}, Age: {age}, Country: {country}")
# ======== > Sets < ===========
# numbers = {1, 2, 3, 4, 5, 5, 5, 2, 4, 6}
# # numbers.add(111)
# numbers.update([33, 34, 35])
# # numbers.remove(100)
# numbers.discard(100)
# print(numbers)
# set1 = {1, 2, 3, 4, 4, 2, 1}
# set2 = {2, 5, 6, 7}
# print("Union : ", set1.union(set2))
# print("Intersection : ", set1.intersection(set2))
# print("Difference: ", set1.difference(set2))
# ========== > Dictionary < ===============
# Student_Data = {
# "name" : "Ishfaq",
# "age" : 25,
# "country" : "Pakistan"
# }
# # print(Student_Data["name"])
# Student_Data["age"] = 20
# Student_Data["city"] = "Trag"
# # print(Student_Data)
# # print(Student_Data.keys())
# # print(Student_Data.values())
# print(Student_Data.items())
# list_dict_keys = list(Student_Data.keys())
# print(list_dict_keys)
# tuple_dict_keys = tuple(Student_Data.keys())
# print(tuple_dict_keys)
# Student_Data.clear()
# print(Student_Data)
# =========== > Nested Dictionary < =========
# Students = {
# "Student1_data" : {"name" : "ishfaq", "age" : 20},
# "Student2_data" : {"name" : "ali", "age" : 25}
# }
# Students["Student1_data"]["name"] = "Hammad"
# print(Students["Student1_data"]["name"])
# print(Students["Student1_data"].keys())