반응형
# list using '[' or ']' keyword for generating list object
# but tuple use '(' or ')' keyword. And tuple is can't change elements after generated.
# tuple is more faster than list
# generate tuple object
t = ('SAMSUNG', 'LG', 'SK')
print(t)
# Also tuple is use index for access elements.
print(t[0])
print(t[1])
print(t[2])
# test: change element value
# It will be comes up some error message.
t[0] = 'Naver'
실행결과
$ py tuple.py
('SAMSUNG', 'LG', 'SK')
SAMSUNG
LG
SK
Traceback (most recent call last):
File "tuple.py", line 16, in <module>
t[0] = 'Naver'
TypeError: 'tuple' object does not support item assignment
반응형
'Programming > Python' 카테고리의 다른 글
[Python-Basic] Class Data Type - 2(Instance) (0) | 2019.11.05 |
---|---|
[Python-Basic] Class Data Type - 1 (0) | 2019.11.05 |
[Python-Basic] Tuple Data Type - 2 (Index) (0) | 2019.11.05 |
[Python-Basic] List Data Type - 5 (Slicing) (0) | 2019.11.05 |
[Python-Basic] List Data Type - 4 (Remove) (0) | 2019.11.05 |