Computer Science/Python

[파이썬] 자료구조의 변경

inee0727 2022. 6. 5. 16:58

다음과 같이 세트를 하나 만들고 type() 을 이용하면 이 데이터가 어떤 형태인지 확인할 수 있다.

menu = {"커피", "우유", "주스"}
print(menu, type(menu)) # menu 의 type 정보 : set

 

▶ 리스트 형태로 변환

menu = list(menu) # 리스트 형태로 변환
print(menu, type(menu)) # menu 의 type 정보 : list

 

▶ 튜플 형태로 변환

menu = tuple(menu) # 튜플 형태로 변환
print(menu, type(menu)) # menu 의 type 정보 : tuple

 

▶ 세트 형태로 변환

 

menu = set(menu) # 세트 형태로 변환
print(menu, type(menu)) # menu 의 type 정보 : set