Zusammenfassung

Datentypen in Python

Jason Myers

Instructor

Sequenz-Datentypen

  • Listen

['Chocolate Chip', 'Peanut Butter']

  • Tupel

('Sugar', 'Eggs')

  • Strings

'Cookies are wonderful'

Datentypen in Python

Dictionaries

  • Sicheres Hinzufügen und Entfernen

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

  • Items entpacken

for field, value in squirrels_by_park.items():

  • Verschachtelte Daten handhaben
for park in squirrels_by_park:
    print(squirrels_by_park[park].get('color', 'N/A'))
Datentypen in Python

Numerische und logische Typen

  • Integer int(1)
  • Float float(1.333333334)
  • Decimal Decimal(5.50)
  • Booleans True or False
  • Sets {'Anzac', 'Oatmeal Raisin'}
Datentypen in Python

Komplexe Datentypen

  • Counter

    Counter(nyc_eatery_types)
    
  • Defaultdicts

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

    namedtuple('Worm', ['species', 'sex', 'mass'])
    
Datentypen in Python

Komplexe Datentypen

  • Dataclasses
@dataclass
class WeightEntry:
    species: str
    flipper_length: int
    body_mass: int
    sex: str
Datentypen in Python

Glückwunsch!

Datentypen in Python

Preparing Video For Download...