Skip to content

Commit 35db9df

Browse files
author
ashegde
committed
feat(examples): list
1 parent e28ccd1 commit 35db9df

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

codes/session_1/list.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Open terminal > python3
2+
# Start typing below commands and see the output
3+
4+
a = [10, 20, 30, 40, 50]
5+
a # [10, 20, 30, 40, 50]
6+
a[0] # 10
7+
a[3] # 40
8+
a[-1] # 50
9+
a[0:3] # [10, 20, 30]
10+
a[3:5] # [40, 50]
11+
a[3:] # [40, 50]
12+
a[:2] # [10, 20]
13+
a[-2:] # [40, 50]
14+
a[:-2] # [10, 20, 30]
15+
16+
a + [60, 70, 80, 90, 100]
17+
18+
a[2] = 300
19+
a # [10, 20, 300, 40, 50]
20+
21+
a.append(250)
22+
a # [10, 20, 300, 40, 50, 250]
23+
24+
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
25+
letters
26+
27+
# Replace some value in letters list
28+
letters[2:4] = ['C', 'D', 'E']
29+
letters # ['a', 'b', 'C', 'D', 'E', 'e', 'f', 'g']
30+
31+
# Remove them
32+
letters[2:4] = []
33+
letters
34+
35+
# Clear list
36+
letters[:] = []
37+
letters # []
38+
39+
# Nested list
40+
a = [1, 2, 3]
41+
b = [4, 5, 6]
42+
x = [a, b]
43+
x # [[1, 2, 3], [4, 5, 6]]
44+
x[0] # [1, 2, 3]
45+
x[0][1] # 2
46+
47+
48+
49+
50+
51+

0 commit comments

Comments
 (0)