-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_three.py
78 lines (63 loc) · 1.73 KB
/
03_three.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
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
# list / Arrays
from random import random
tea_varieties = ["Black", "Green", "Oolong", "White"]
# print(tea_varieties)
# ['Black', 'Green', 'Oolong', 'White']
# indexing accessing
# print(tea_varieties[1])
# Green
# print(tea_varieties[-1])
# White
# print(tea_varieties[:2])
# ['Black', 'Green']
# print(tea_varieties[2:])
# ['Oolong', 'White']
# tea_varieties[3] = "Harbal"
# print(tea_varieties)
# # ['Black', 'Green', 'Oolong', 'Harbal']
# for loop
# for i in tea_varieties:
# print(i, end ="-")
# Black-Green-Oolong-White-
# if "Oolong" in tea_varieties:
# print("Yes i have Oolong tea!")
# # Yes i have Oolong tea!
# tea_varieties.append("Tapri Chai")
# print(tea_varieties)
# # ['Black', 'Green', 'Oolong', 'White', 'Tapri Chai']
# print(tea_varieties)
# print(tea_varieties.pop())
# print(tea_varieties)
# ['Black', 'Green', 'Oolong', 'White']
# White
# ['Black', 'Green', 'Oolong']
# tea_varieties.remove("Green")
# print(tea_varieties)
# Green is removed
# insertion
# tea_varieties.insert(1, "Red Chai")
# print(tea_varieties)
# ['Black', 'Red Chai', 'Green', 'Oolong', 'White']
# same reference of tea_variety is there
# tea_varieties_copy = tea_varieties
# resolving copy error
# both references are different
# tea_varieties_copy = tea_varieties.copy()
#
# tea_varieties_copy.append("Lemon")
# print(tea_varieties)
# # ['Black', 'Green', 'Oolong', 'White']
# # ['Black', 'Green', 'Oolong', 'White', 'Lemon']
# print(tea_varieties_copy)
# # list comprehension
# generating squared nums list
# squared_nums = [x**2 for x in range(10)]
# print(squared_nums)
# # [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
# print(range(10))
# y= range(10)
# # range(0, 10)
# print(y)
# range(0, 10)
# squared_nums = [x**2 for x in range(9)]
# print(squared_nums)