Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ทำไม Python Exceptions ชื่อลงท้าย Error (ZeroDivisionError, NameError)

เหตุผลที่ชื่อลงท้าย Error:

  1. สั้นกว่า Exception ประหยัดตัวอักษร ไม่สูญเสียความหมาย
  2. Historical reason: ใน Python แยก "Errors" (syntax errors) กับ "Exceptions" (runtime) แต่ naming convention คงอยู่
  3. ไม่ใช่ทุก Exceptions ที่เป็น Errors: SystemExit, KeyboardInterrupt, StopIteration, GeneratorExit เป็น Exceptions ไม่ใช่ Errors
  4. มี Exception class ชื่อ Warning และ subclasses หลายตัว

คลาสไม่มีคำว่า "class" ตัวแปรไม่มีคำว่า "variable" เหมือนกัน