-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson3_loops.py
More file actions
31 lines (26 loc) · 923 Bytes
/
lesson3_loops.py
File metadata and controls
31 lines (26 loc) · 923 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
30
31
'''
This lesson we will demonstrate how to iterate the items in lists
Python does not have many of the diffent looping forms as other traditional languages
Python uses only the "for" and "while" to iterate through items in lists
'''
#We will start with the same list from form the other examples
list1 = ['red', 'blue', 'green']
dict1 = {
"make":"chevy",
"model":"cavelier",
"year": 1990
}
# The "for" loop will iterate through list1 and print all the items in the list
for items in list1:
print('color is '+items)
# This "for" loop will capture the key and value from the dictionary list
for key,val in dict1.items():
print('this is the key: '+key)
print('this is the value: '+str(val))
print('this is the key:value pairing '+key+':'+str(val))
# This example of a "while" loop
# The "while" loop will remain "true" until i becomes greater than 6
i = 1
while i < 6:
print(i)
i += 1