まとめ

Python のデータ型

Jason Myers

Instructor

シーケンス型

  • リスト

['Chocolate Chip', 'Peanut Butter']

  • タプル

('Sugar', 'Eggs')

  • 文字列

'Cookies are wonderful'

Python のデータ型

辞書

  • 安全な追加と削除

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

  • アンパック

for field, value in squirrels_by_park.items():

  • ネストデータの処理
for park in squirrels_by_park:
    print(squirrels_by_park[park].get('color', 'N/A'))
Python のデータ型

数値型と論理型

  • 整数 int(1)
  • 浮動小数点数 float(1.333333334)
  • Decimal Decimal(5.50)
  • ブール値 True or False
  • セット {'Anzac', 'Oatmeal Raisin'}
Python のデータ型

複合データ型

  • 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'])
    
Python のデータ型

複合データ型

  • データクラス
@dataclass
class WeightEntry:
    species: str
    flipper_length: int
    body_mass: int
    sex: str
Python のデータ型

お疲れさまでした!

Python のデータ型

Preparing Video For Download...