a = {'Korea': 'Seoul',
'Canada': 'Ottawa',
'USA': 'Washington D.C'}
b = {0:1, 1:6, 7:9, 8:10}
a = {'Korea': 'Seoul',
'Canada': 'Ottawa',
'USA': 'Washington D.C'}
a['Japan'] = 'Tokyo'
a['Japan'] = 'Kyoto'
a['Japan2'] = 'Kyoto'
a['China'] = 'Beijing'
print(a)
"""
{'Korea': 'Seoul', 'Canada': 'Ottawa',
'USA': 'Washington D.C', 'Japan': 'Kyoto',
'Japan2': 'Kyoto', 'China': 'Beijing'}
"""
a = {'a': 1, 'b': 2, 'c' : 3}
b = {'a': 2, 'd': 4, 'e': 5}
a.update(b)
print(a) # {'a': 2, 'b': 2, 'c': 3, 'd': 4, 'e': 5}
a = {'a': 1, 'b': 2, 'c' : 3}
print(a) # {'a': 1, 'b': 2, 'c': 3}
del a['b'] # a.pop('b')
print(a) # {'a': 1, 'c': 3}
a = {'a': 1, 'c' : 3}
print(a) # {'a': 1, 'c': 3}
a.clear()
print(a) # {}
a = {'a': 1, 'b': 2, 'c' : 3}
b = [1, 2, 3, 4, 5, 6, 7, 9, 10, 100]
print(100 in b) # Ture
print(2 in a) # False
a = {'a': 1, 'b': 2, 'c' : 3}
print(a.get('d')) # print(a['d']) -> None
모든 keys, values 접근
a = {'a': 1, 'b': 2, 'c' : 3}
print(a) # {'a': 1, 'b': 2, 'c': 3}
print(list(a.keys())) # ['a', 'b', 'c']
print(list(a.values())) # [1, 2, 3]
list(a.items()) # [('a', 1), ('b', 2), ('c', 3)]
a = {1, 1, 2, 3, 3, 4, 1, 5}
print(a) # {1, 2, 3, 4, 5}
a = [1, 1, 2, 3, 3, 4, 1, 5]
print(a) # [1, 1, 2, 3, 3, 4, 1, 5]
b = set(a)
print(b) # {1, 2, 3, 4, 5}
a = {1, 2, 3}
b = {2, 3, 4}
print(a.union(b)) # 합집합 {1, 2, 3, 4}
print(a.intersection(b)) # 교집합 {2, 3}
print(a.difference(b)) # 차집합 {1}
print(a.issubset(b)) #부분 집합 False
Logical AND, OR, NOT
논리표
a, b, c = 10, 8, 11
if (a == 10 or b == 9) and c == 12: # (T or F) and F -> F
print('that is true')
if not a == 10: # not T -> F
print('a is ten')
if의 조건이 bool이 아닌 경우
if, else
# 짝수인 경우에는 2로 나눈 값을 출력하고
# 홀수인 경우에는 1을 더한 값을 출력해라
a = 12
if a % 2 == 0: # 짝수인지 판별
print(a / 2)
else:
print(a + 1)
if, elif, else
중첩 조건문
a, b, c = 10, 9, 8
if a == 10:
if c == 8:
if b == 8:
print('a is ten and b is 8')
else:
print('a is ten and b is not 8')
머신러닝과 데이터 분석 A-Z 올인원 패키지 Online. 👉 https://bit.ly/3cB3C8y