ควิซ Python Type Hints

This Python quiz checks how well you understand type hints, from int | None and list[str] to Callable, Literal and NamedTuple. It also tests the most common misunderstanding of all - that Python checks your hints when the code runs.

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

เลือกโหมด

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

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

ข้อ 1 จาก 10

What does this print?

def add(a: int, b: int) -> int:
    return a + b

print(add("4", "2"))
ดูเฉลย

C. 42 Python does not check type hints when the code runs. The two strings are simply joined with +, giving 42. A static checker like mypy would flag this call before you run it.

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

  • Hints are not enforced at run time
  • int | None, list[str] and dict[str, int]
  • Callable, Literal and NamedTuple
  • __annotations__ and static checkers like mypy
  • Hints and isinstance()

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

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

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

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

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

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

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