728x90
반응형
개요
- List와 유사하나 Tuple은 불변의 특징이 존재
- List와 다르게 값을 원하는 곳에 추가하거나 제거할 수 없음
- Tuple은 값이 하나라도 , 을 명시해야 함
- Tuple의 언패킹으로 값을 치환해서 사용가능 (불 = a, 전기 = b, 물 = c)
## tuple
type_tup='불', '전기', '물', '풀'
print(type(type_tup))
# <class 'tuple'>
print(type_tup[0])
# 불
new_tup='악',
print(type(new_tup))
# <class 'tuple'>
type_tup = type_tup + new_tup
print(type_tup)
#('불', '전기', '물', '풀', '악')
a, b, c, d, e = type_tup
print(a) # 불
print(b) # 전기
a, b = b, a
print(a) # 전기
print(b) # 불
## tuple -> list
type_tup = list(type_tup)
print(type(type_tup))
# <class 'list'>
print(type_tup)
#['불', '전기', '물', '풀', '악']
728x90
'*Programming > [ Py ] Python' 카테고리의 다른 글
[Py - N06] Dictionary (0) | 2022.08.28 |
---|---|
[Py - N05] Set (중복제거) (0) | 2022.08.28 |
[Py - N03] List (0) | 2022.08.28 |
[Py - N02] Format String (0) | 2022.08.28 |
[Py - N01] print( ) 과 input( ) (0) | 2022.08.28 |