PYTHON PROGRAMMING 기초

DICTIONARIES AND BOOLEANS

DICTIONARIES

dict()
{}
my_phone = {'brand' : 'apple','model' : 'iphone X', 'year' : 2018}
my_phone
{'brand': 'apple', 'model': 'iphone X', 'year': 2018}

한쌍 : item , 아이템 왼쪽은 key , 오른쪽은 value

my_phone['brand']
'apple'
my_phone['model']
'iphone X'
my_phone['year']
2018
my_phone.get('brand')
'apple'
my_phone.get('color')
'red'
my_phone
{'brand': 'apple', 'model': 'iphone X', 'year': 2018}
my_phone['model'] = "iphone 12"
my_phone
{'brand': 'apple', 'model': 'iphone 12', 'year': 2018}
my_phone['year'] = 2021
my_phone
{'brand': 'apple', 'model': 'iphone 12', 'year': 2021}
my_phone['color'] = 'red'
my_phone
{'brand': 'apple', 'model': 'iphone 12', 'year': 2021, 'color': 'red'}
del my_phone['model']
my_phone
{'brand': 'apple', 'year': 2021, 'color': 'red'}

키,벨류로 매칭값 찾기

my_phone.keys()
dict_keys(['brand', 'year', 'color'])
my_phone.values()
dict_values(['apple', 2021, 'red'])
my_phone.items()
dict_items([('brand', 'apple'), ('year', 2021), ('color', 'red')])

항목 찾기

'brand' in my_phone
True
'brand' not in my_phone
False
'apple' in my_phone.values()
True

clear() 함수 호출을 이용하여 내용지우기

my_list = [1,2,3,4,5]
my_list.clear()
my_list
[]
my_phone.clear()
my_phone
{}

BOOLEANS

True or False
True