동영상 강좌는 유튜브 채널 '웹학교'를 이용하시기 바랍니다.
Tuple
튜플은 순서가 있고 변경할 수 없는 컬렉션입니다. 파이썬 튜플은 둥근 괄호로 싸여 있습니다.
Tuple 만들기
thistuple = ("apple", "banana", "cherry")
print(thistuple)
위치1 항목 구하기
thistuple = ("apple", "banana", "cherry")
print(thistuple[1])
tuple에서는 항목의 값을 변경할 수 없습니다.
아래 코드는 오류가 발생합니다.
thistuple = ("apple", "banana", "cherry")
thistuple[1] = "blackcurrant" # test changeability
print(thistuple)
tuple()생성자
tuple()생성자를 사용하여 tuple을 생성할 수 있습니다. len()함수는 tuple의 길이를 반환합니다.
tuple()메소드를 사용하여 tuple만들기
thistuple = tuple(("apple", "banana", "cherry")) # note the double round-brackets
print(thistuple)
len()메소드는 tuple내 항목 갯수를 반환합니다.
thistuple = tuple(("apple", "banana", "cherry"))
print(len(thistuple))
**
tuple의 항목은 제거할 수 없습니다.
등록된 댓글이 없습니다.