for loop
1
words = ['cat', 'window', 'defenestrate']
2
for w in words:
3
print(w, len(w))
4
​
5
#cat 3
6
#window 6
7
#defenestrate 12
Copied!
1
for i in range(5):
2
print(i)
3
#0
4
#1
5
#2
6
#3
7
#4
8
​
Copied!
range(5, 10)
5, 6, 7, 8, 9
range(0, 10, 3)
0, 3, 6, 9
range(-10, -100, -30)
-10, -40, -70
1
a = ['Mary', 'had', 'a', 'little', 'lamb']
2
for i in range(len(a)):
3
print(i, a[i])
4
5
#0 Mary
6
#1 had
7
#2 a
8
#3 little
9
#4 lamb
Copied!
Last modified 1yr ago
Copy link