ควิซ Python 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().

ปานกลาง 10 ข้อ ~6 นาที ผ่านที่ 80% Python 3.12

เลือกโหมด

กำลังเล่นแบบผู้เยี่ยมชม: เข้าสู่ระบบเพื่อเก็บ XP และ streak

ตัวอย่างคำถาม

ข้อ 1 จาก 10

What does this print?

from dataclasses import dataclass

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

print(Point(1))
ดูเฉลย

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.

ควิซนี้มีเนื้อหาอะไรบ้าง

  • 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

คำถามที่พบบ่อย

ต้องมีบัญชีไหม?

ไม่ต้อง ใครก็เล่นได้ เข้าสู่ระบบเพื่อเก็บ XP, streak, เหรียญตรา และประวัติ

ใช้ Python เวอร์ชันไหน?

Python 3.12 ทุกคำถามเกี่ยวกับผลลัพธ์ผ่านการรันโค้ดจริงเพื่อตรวจสอบแล้ว

ทำซ้ำได้ไหม?

ได้ ระบบเก็บคะแนนที่ดีที่สุดไว้ และสลับคำถามกับตัวเลือกใหม่ทุกครั้ง