跳转到内容

Python語法及語義

维基百科,自由的百科全书

这是本页的一个历史版本,由Cuaxdon留言 | 贡献2021年10月6日 (三) 08:54 (新條目)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)

Python 語法及語義(Python syntax and semantics),Python 編程語言的語法是一組規則,用於定義 Python 程序將如何編寫與解釋(由運行時系統及人類讀者)。 [1]Python 語言與 Perl、C 以及 Java 有許多相似之處。 不過,在這些語言之間仍存在著一些明確的差異。

關鍵字

Python有35個關鍵字保留字;這些關鍵字或保留字不能用作標識符[2][3]

  • and
  • as
  • assert
  • async[note 1]
  • await[note 1]
  • break
  • class
  • continue
  • def
  • del
  • elif
  • else
  • except
  • False[note 2]
  • finally
  • for
  • from
  • global
  • if
  • import
  • in
  • is
  • lambda
  • None
  • nonlocal[note 3]
  • not
  • or
  • pass
  • raise
  • return
  • True[note 2]
  • try
  • while
  • with
  • yield
註解
  1. ^ 1.0 1.1 async and await were introduced in Python 3.5.[4]
  2. ^ 2.0 2.1 True and False became keywords in Python 3.0. Previously they were global variables.
  3. ^ nonlocal was introduced in Python 3.0.

註釋

  1. ^ "Readability counts." - PEP 20 - The Zen of Python
  2. ^ 2. Lexical analysis. Python 3 documentation. Python Software Foundation. [2021-03-11]. 
  3. ^ 2. Lexical analysis. Python v2.7.18 documentation. Python Software Foundation. [2021-03-11]. 
  4. ^ New Keywords. Python v3.5 documentation. Docs.python.org. [2016-06-01]. (原始内容存档于2016-06-18). 

外部連結