forked from CodexploreRepo/python-youtube-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path#9_Loop.py
More file actions
29 lines (22 loc) · 658 Bytes
/
#9_Loop.py
File metadata and controls
29 lines (22 loc) · 658 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
#LOOP: For & While
my_list = [1,2,3]
my_tuple = (1,2,3)
my_list2 = [(1,2), (3,4), (5,6)]
my_dict = {'a': 1, 'b': 2. 'c': 3}
for num in my_list:
print(num) # 1, 2, 3
for num in my_tuple:
print(num) # 1, 2, 3
for num in my_list2:
print(num) # (1,2), (3,4), (5,6)
for num in '123':
print(num) # 1, 2, 3
for k,v in my_dict.items(): #Dictionary Unpacking
print(k) # 'a', 'b', 'c'
print(v) # 1, 2, 3
while <condition that evaluates to boolean>:
# action
if <condition that evaluates to boolean>:
break # break out of while loop
if <condition that evaluates to boolean>:
continue #continue to the next line in the block