Tổng kết

Các kiểu dữ liệu trong Python

Jason Myers

Instructor

Kiểu dữ liệu tuần tự

  • List (danh sách)

['Chocolate Chip', 'Peanut Butter']

  • Tuple (bộ)

('Sugar', 'Eggs')

  • String (chuỗi)

'Cookies are wonderful'

Các kiểu dữ liệu trong Python

Dictionary

  • Thêm/xóa an toàn

squirrels_by_park.pop("City Hall Park", {})

  • Unpack phần tử

for field, value in squirrels_by_park.items():

  • Xử lý dữ liệu lồng nhau
for park in squirrels_by_park:
    print(squirrels_by_park[park].get('color', 'N/A'))
Các kiểu dữ liệu trong Python

Kiểu số và logic

  • Số nguyên int(1)
  • Số thực float(1.333333334)
  • Số thập phân Decimal(5.50)
  • Boolean True or False
  • Set (tập hợp) {'Anzac', 'Oatmeal Raisin'}
Các kiểu dữ liệu trong Python

Kiểu dữ liệu phức tạp

  • Counter

    Counter(nyc_eatery_types)
    
  • Defaultdict

    eateries_by_park = defaultdict(list)
    for park_id, name in nyc_eateries_parks:
      eateries_by_park[park_id].append(name)
    
  • Namedtuple

    namedtuple('Worm', ['species', 'sex', 'mass'])
    
Các kiểu dữ liệu trong Python

Kiểu dữ liệu phức tạp

  • Dataclass
@dataclass
class WeightEntry:
    species: str
    flipper_length: int
    body_mass: int
    sex: str
Các kiểu dữ liệu trong Python

Chúc mừng!

Các kiểu dữ liệu trong Python

Preparing Video For Download...