Python

list, tuples, dictionary

한고운 2024. 8. 31. 04:28
# list
day_of_week = ["Mon", "Tue", "Wed", "Thu", "Fri"]
print(day_of_week[2])

day_of_week.append("sun")
print(day_of_week)

day_of_week.remove("sun")
print(day_of_week)

day_of_week.clear()
print(day_of_week)

# Tuples : 불변
days = ("Mon", "Tue", "Wed", "Thu", "Fri")
print(days[-1])

# dictionary : kdy - value 키-값
player = {
  'name': 'gowoon',
  'age': 42,
  'alive': True,
  'fav_food': ["피자", "햄버거"]
}
print(player)

print(player.get('fav_food'))
print(player['fav_food'])
print(player)

player.pop('age')
print(player)

player['xp'] =1500
print(player)

player['fav_food'].append("국수")
print(player.get('fav_food'))
print(player['fav_food'])

실행결과