Python

[Python]Tuple

sagesse2021 2021. 11. 14. 16:20
반응형
x = (1,2,3)
y = ('a','b','c')
z = (1,"hello","there")

print(x + y)
print('a' in  y)
print(z.index(1))

//(1,2,3,'a','b','c')

//True

//0

  • list에서 썼던 function들을 tuple에서도 그대로 쓸 수 있다
x = (1,2,3)
y = ('a','b','c')
z = (1,"hello","there")

# mutable  vs immutable 
x[0] = 10  #error
  • list와 tuple의 차이점 : list와 달리 tuple에서는 assignment(=튜플 안의 값을 업데이트 하는 것)을 할 수x
  • 튜플 안에 있는 것들은 바꿀 수 없다
  • 가변(mutable) : 값을 바꿀 수 있음
  • 불변(immutable) :값을 바꿀 수 없음
  • 리스트는 mutable, 튜플은 immutable
반응형

'Python' 카테고리의 다른 글

[Python]과일 숫자 세는 프로그램 만들기(list, 조건문 사용)  (0) 2021.11.15
[Python]Dictionary  (0) 2021.11.15
[Python]List  (0) 2021.11.14
[Python]조건문  (0) 2021.11.13
[Python]Return  (0) 2021.11.13