#튜플tuple () : 여러 개의 값을 하나로 묶는 자료형
#한 번 만들면 절대 바꿀 수 없다!!

color = ('빨강', '주황', '노랑', '초록', '파랑', '남색', '보라')
#1. 인덱싱, 슬라이싱을 할 수 있다
print(color[2])
print(color[1:5])

page = [(1,2), (3,4), (5,6)]
print(page[1])
print(page[2][0])

#2. 원소를 조회in하고, 길이len()를 확인할 수 있다
print('주황' in color)
print(len(color))

#3. 더하기+ 곱하기* 연산을 할 수 있다
print(color + (2, 3))
print((3,) * 5)

#4. 원소의 수정, 추가, 삭제가 불가능하다
#color[0] = '검정'
#color.append('분홍')
#color.remove('노랑')

#🍓 문제: 내가 좋아하는 과일!
#좋아하는 과일을 3개 이상 입력해서 튜플에 저장하세요.
fruits = ('수박', '포도', '파인애플', '사과')

#두 번째로 입력한 과일을 인덱스를 이용해서 출력하세요.   
print(fruits[1])

#'사과' 가 fruits 튜플 안에 있는지 조회하세요.
print('사과' in fruits)

#총 과일 개수를 출력하세요.
print(len(fruits))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: