keyword --- 檢驗Python關鍵字?

源碼: Lib/keyword.py


This module allows a Python program to determine if a string is a keyword or soft keyword.

keyword.iskeyword(s)?

如果 s 是一個 Python 關鍵字 則返回 True。

keyword.kwlist?

包含解釋器定義的所有 關鍵字 的序列。 如果所定義的任何關鍵字僅在特定 __future__ 語句生效時被激活,它們也將被包含在內。

keyword.issoftkeyword(s)?

Return True if s is a Python soft keyword.

3.9 新版功能.

keyword.softkwlist?

Sequence containing all the soft keywords defined for the interpreter. If any soft keywords are defined to only be active when particular __future__ statements are in effect, these will be included as well.

3.9 新版功能.