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

Reserved Keywords ใน Python 3 (33 คำสงวน)

Keywords มีความหมายพิเศษใน Syntax ไม่สามารถใช้เป็น Identifier (ชื่อตัวแปร ฟังก์ชัน คลาส) ได้

รายการ Keywords Python 3 (33 คำ)

andexceptlambdawith
asfinallynonlocalwhile
assertfalseNoneyield
breakfornot
classfromor
continueglobalpass
defifraise
delimportreturn
elifinTrue
elseistry

Python 2 vs 3

  • Python 2: 30 Keywords (มี print, exec)
  • Python 3: 33 Keywords (print → Function, เพิ่ม nonlocal, False/True/None เป็น Keyword)

ดูรายการใน Interpreter

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', ...]
เคล็ดลับ: IDE 部分会 Highlight Keywords ให้อัตโนมัติ ช่วยป้องกันการใช้ผิด