#튜플 () : 여러 개의 값을 하나로 묶어서 저장하는 자료형
# 한 번 만들면 절대 수정할 수 없음!! 불변
color = ('red', 'yellow', 'green', 'blue')

#1. 인덱싱과 슬라이싱이 가능하다 - 순서가 있는 자료형
print(color[2])
print(color[1:3])

#2. 값을 조회할 수 있다 - in 
print('orange' in color)

#3. 길이를 확인할 수 있다 - len
print(len(color))

#4. 더하기, 곱하기 연산 가능
print(color + (2, 3, 4))
print((3,) * 5)

#5. 수정할 수 없다
#color[0] = 'orange'


#딕셔너리 {key:value} key와 value를 짝지어 저장하는 자료형
#순서가 없는 자료형
student = {'name':'박주현', 'age':15}

#딕셔너리 메서드
print(student.keys())
print(student.values())
print(student.items())

#딕셔너리 사용법
print(student['name'])
print(student['age'])

#새로운 key 추가
student[(1, 2, 3)] = [4, 5] #딕셔너리[key] = value
print(student)
#student[[4, 5]] = (1, 2, 3) key는 불변의 자료형만 사용할 수 있다
student['age'] = 20 #key는 중복될 수 없다
print(student)

#삭제
del student['name']
print(student)

print('-----문제-----')
fruits = {'사과':'apple','바나나':'banana','체리':'cherry'}
print(fruits)

#바나나의 영어가 출력되도록 만들어보세요
print(fruits['바나나'])

#사과를 삭제해봅시다
del fruits['사과']
print(fruits)
#딸기를 추가해봅시다
fruits['딸기'] = 'strawberry'
print(fruits)


Embed on website

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