소개 및 리스트

Python의 데이터 타입

Jason Myers

Instructor

데이터 타입

  • 데이터 타입 시스템은 언어의 기능을 좌우합니다
  • 데이터 타입을 이해하면 데이터 과학자로서 역량을 높일 수 있습니다
Python의 데이터 타입

컨테이너 시퀀스

  • 다른 타입의 데이터를 담습니다
  • 집계, 정렬 등에 사용됩니다
  • 가변(list, set) 또는 불변(tuple)일 수 있습니다
  • 반복 가능합니다
Python의 데이터 타입

리스트

  • 추가된 순서대로 데이터를 저장합니다
  • 가변적입니다
  • 인덱스를 가집니다
Python의 데이터 타입

리스트의 개별 항목 접근하기

cookies = ['chocolate chip', 'peanut butter', 'sugar']
cookies.append('Tirggel')
print(cookies)
['chocolate chip', 'peanut butter', 'sugar', 'Tirggel']
print(cookies[2])
sugar
Python의 데이터 타입

리스트 결합하기

  • 연산자를 사용하면 두 리스트를 결합해 새 리스트를 만들 수 있습니다
cakes = ['strawberry', 'vanilla']

desserts = cookies + cakes

print(desserts)
['chocolate chip', 'peanut butter', 'sugar', 'Tirggel', 'strawberry', 'vanilla']
  • .extend() 메서드는 리스트를 다른 리스트의 끝에 병합합니다
cookies.extend(cakes)
Python의 데이터 타입

리스트에서 요소 찾기

  • .index() 메서드는 리스트에서 데이터 요소의 위치를 찾습니다
position = cookies.index('sugar')

print(position)
2
Python의 데이터 타입

리스트에서 요소 제거하기

  • .pop() 메서드는 리스트에서 항목을 제거하고 해당 값을 저장할 수 있게 합니다
name = cookies.pop(position)

print(name)
sugar
print(cookies)
['chocolate chip', 'peanut butter', 'Tirggel']
Python의 데이터 타입

리스트 반복하기

  • 리스트 컴프리헨션(List comprehension)은 리스트를 반복하면서 각 요소에 작업을 수행하는 일반적인 방법입니다
titlecase_cookies = [cookie.title() for cookie in cookies]
print(titlecase_cookies)
Chocolate Chip
Peanut Butter
Tirggel
Python의 데이터 타입

리스트 정렬하기

  • sorted() 함수는 데이터를 숫자 또는 알파벳 순서로 정렬해 새 리스트를 반환합니다
print(cookies)
['chocolate chip', 'peanut butter', 'Tirggel']
sorted_cookies = sorted(cookies)

print(sorted_cookies)
['Tirggel', 'chocolate chip', 'peanut butter']
Python의 데이터 타입

연습해 봅시다!

Python의 데이터 타입

Preparing Video For Download...