Python-Quiz: Dataclasses & Enums

This Python quiz covers @dataclass and the enum module, two standard library tools that remove a lot of boilerplate. You will predict the generated __repr__ and __eq__, avoid the mutable default trap, and work with enum names, values and auto().

Mittel 10 Fragen ~6 Minuten Bestanden ab 80% Python 3.12

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 10

What does this print?

from dataclasses import dataclass

@dataclass
class Point:
    x: int
    y: int = 0

print(Point(1))
Lösung zeigen

C. Point(x=1, y=0) @dataclass writes __init__ and __repr__ from the annotated fields. The repr shows each field by name, and y uses its default 0.

Darum geht es in diesem Quiz

  • What @dataclass generates for you
  • Defaults, field(default_factory=...) and field order
  • frozen=True and order=True
  • Enum members, .name, .value and lookup by value
  • auto() and comparing enums

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Welche Python-Version?

Python 3.12. Jede Frage zur Ausgabe wurde geprüft, indem der Code ausgeführt wurde.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.