-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterables.py
More file actions
64 lines (40 loc) · 1.11 KB
/
iterables.py
File metadata and controls
64 lines (40 loc) · 1.11 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Iterables = An object/collection that can return its elements one at a time,
# allowing it to be iterated over in a loop
from dis import print_instructions
numbers = [1, 2, 3, 4, 5]
for number in numbers:
print(number, end=" ")
print()
for number in reversed(numbers):
print(number, end=" ")
print()
numbers = (1, 2, 3, 4, 5)
for number in numbers:
print(number, end=" ")
print()
fruits = {"apple", "banana", "orange", "coconut"}
for fruit in fruits: # set이라 순서가 없어서 print는 랜덤
print(fruit, end=" ") # reversed(fruits)는 안됨
print()
name = "Yoo Janghun"
for char in name:
print(char, end=" ")
print()
user = {
"name": "janghun",
"age": 23,
"is_student": True
};
for info in user:
print(info, end=" ")
print()
for info_val in user.values():
print(info_val, end=" ")
print()
for info_key in user.keys():
print(info_key, end=" ")
print()
for info_key, info_val in user.items():
print(f"{info_key} : {info_val}")
print()
print(user.items()) # dict_items([('name', 'janghun'), ('age', 23), ('is_student', True)])