Skip to content

Commit bfc9ec0

Browse files
author
ashegde
committed
feat(examples): loops
1 parent 23e6d11 commit bfc9ec0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

codes/session_2/loop.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Open terminal > python3 loop.py
2+
# Start typing below commands and see the output
3+
4+
animals = ['cat', 'dog', 'racoon']
5+
for a in animals:
6+
print(a, len(a))
7+
8+
print('\n')
9+
10+
for i in range(5):
11+
print(i)
12+
13+
print('\n')
14+
15+
for i in range(5, 10):
16+
print(i)
17+
18+
print('\n')
19+
20+
# (range start, range end, step)
21+
for i in range(0, 10, 3):
22+
print(i)
23+
24+
print('\n')
25+
26+
for i in range(-10, -100, -30):
27+
print(i)
28+
29+
print('\n')
30+
31+
a = ['My', 'name', 'is', 'Ashwin']
32+
for i in range(len(a)):
33+
print(i, a[i])
34+
35+
print('\n')

0 commit comments

Comments
 (0)