Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 주피터노트북그래프
- 주피터노트북데이터분석
- SQL수업
- SQL
- SQLSCOTT
- 판다스그래프
- 파이썬데이터분석주피터노트북
- python알고리즘
- 수업기록
- 주피터노트북
- 파이썬차트
- 파이썬알고리즘
- 파이썬크롤링
- python수업
- matplotlib
- 데이터분석시각화
- 팀플기록
- 파이썬데이터분석
- sql따라하기
- 파이썬
- 주피터노트북맷플롯립
- 주피터노트북판다스
- 판다스데이터분석
- 파이썬시각화
- sql연습
- Python
- 맷플롯립
- sql연습하기
- python데이터분석
- 파이썬수업
Archives
- Today
- Total
IT_developers
Python 개념 및 실습 - tuple 본문
tuple
- 리스트와 비슷
- ()로 둘러싸여 있음
- 리스트는 값의 생성, 삭제, 수정이 가능하지만 튜플은 변경은 불가함
# 생성
t1 = ()
t2 = (1, 2, 3)
t3 = (1,) # 1개의 요소만을 가질 때 요소 뒤에 콤마 반드시 필요
t4 = 4, 5, 6 # 괄호 생략 가능
t5 = ("a", "b", ("c", "d"))
print(t1)
print(t2)
print(t3)
print(t4)
print(t5)

# 인덱싱/ 슬라이싱
# del t2[1] #TypeError: 'tuple' object doesn't support item deletion
# t2[1] = 5 #TypeError: 'tuple' object does not support item assignment
print("t2[1]", t2[1])
print("t2[0:3]", t2[0:3])
print("t4[1] + t4[2]", t4[1] + t4[2])
print("t3 * 2", t3 * 2)
# 튜플 ==> 리스트로 변환, 리스트 ==> 튜플 변환
print(list(t4))
list1 = list(t4)
list1[2] = 7
print(list1)
# t4 ==> 리스트
t4 = tuple(list1)
print(t4)

'Python' 카테고리의 다른 글
Python 개념 및 실습 - set (0) | 2022.09.07 |
---|---|
Python 개념 및 실습 - dictionary (0) | 2022.09.07 |
Python 개념 및 실습 - list(3) (0) | 2022.09.06 |
Python 개념 및 실습 - list(2) (0) | 2022.09.05 |
Python 개념 및 실습 - list(1) (0) | 2022.09.05 |
Comments