forked from vandanagarg/practice_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor loop
More file actions
29 lines (23 loc) · 736 Bytes
/
for loop
File metadata and controls
29 lines (23 loc) · 736 Bytes
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
#for loop
# special kind of loop as it helps us to loop over a different collections of items
#string
for letter in "Giraffe Academy ":
print(letter)
#array
freinds = ["Jim", "Karen", "Kevin"]
for freind in freinds:
print(freind)
#number
for index in range(10): #o/p will be from 0 to 9 vertically
print(index)
for index in range(3,10): #o/p will be from 3 to 9 vertically
print(index)
for index in range(len(freinds)):
print(index) #o/p will be index of array i.e: 0 1 2 vertically
print(freinds[index]) #o/p will be name of freinds array vertically
#another random example
for index in range(5):
if index == 0:
print("First iteration !")
else:
print("Not first")