python_09
2021. 1. 29. 18:43ㆍpython
# 자료형
#1.4 튜플
#1.4.1 개요 리스트와 거의 모두 동일하다 다만 묶음이 소괄호()로 되어 있다 또한 값의 수정 삭제 생성등이 불가능하다.
#문자열(%,.format,f) ,딕셔너리 자료형 {} 리스트 [] 튜플자료형()
#1.4.2 유형과 특징 t1=() t2=(1,) t3 =(1,2,3) t4=1,2,3,4 t5=('a','b',('ab','cd'))
#t6 = (1, 2, 'a', 'b')
# print(t6)
# t6[0] = 4
# print(t6) # TypeError: 'tuple' object does not support item assignment(수정불가)
#del t6[0] # TypeError: 'tuple' object doesn't support item deletion (삭제불가)
a=(1,2,'a','b')
b=(3,4,'c','d')
print(a[0],b[3]) # 인덱싱
print(a[0:2],b[0:4]) #슬라이싱
print(a+b) #연산
print(a*4)
a,b = (1,2,3),(4, )
a,b = (1, 2, 3), (4,)
# a, b = (1, 2, 3), (4) #TypeError: can only concatenate tuple (not "int") to tuple
print(a,b)
a= a+b
print(a) #새로 생성된 것이 아니라 값이 더해졌다