`return` 或 `del` 的类型是什么?

What is the type of `return` or `del`?

我不认为它们是函数,我不能使用 type(return) 来获得答案(它会引发错误)。

他们叫什么?我可以定义类似的东西吗?

returndel 语句 。它们不是对象,所以它们没有类型。语句构成语言的语法,对象构成语法操作的数据模型。

Simple Statements reference page for their documentation. There are also Compound Statements;包含多组语句的语句。

因为delreturn都是语句,所以它们的名字也是reserved keywords,这意味着你不能用它们来创建标识符。语句中使用的所有单词都是关键字*,但并非所有关键字都是语句(的一部分)。

您不能在 Python 本身中定义自己的语句,您必须扩展语言实现本身(因此扩展 Python 语法、分词器、解析器、AST 模型和解释器)。


* 当前例外是 async and await which are temporarily not keywords outside of coroutines to help transition existing code to Python 3.5; making them keywords now would potentially break too much existing code that doesn't yet use coroutines anyway. See the PEP 492 transition plan; the plan is to make them keywords in Python 3.7.