gpt4 book ai didi

python - Python 中 'special' 运算符/指令的类型是什么?

转载 作者:太空宇宙 更新时间:2023-11-04 06:48:14 25 4
gpt4 key购买 nike

在 Python 中,我们有 ifelifelsebreakcontinue 这样的东西pass 等。为了找个更好的词,我称它们为特殊说明。

它们是什么类型的?如果我执行类似type(pass) 的操作,我会得到一个SyntaxError

最佳答案

根据文档,您要查找的术语是 "Keywords" .

2.3.1. Keywords

The following identifiers are used as reserved words, or keywords ofthe language, and cannot be used as ordinary identifiers. They must bespelled exactly as written here:

False      class      finally    is         return
None continue for lambda try
True def from nonlocal while
and del global not with
as elif if or yield
assert else import pass
break except in raise

这些是语言结构。它们是语言的一部分 grammar and syntax ,并且不是对象。口译员以不同的方式对待这些。因此,它们不像对象通常那样与类型相关联。

如果出于任何原因,你想知道一个词是否是 python 关键字(又名,保留字),你可以导入 keyword 模块并测试 -

import keyword

keyword.iskeyword('if')
True

关于python - Python 中 'special' 运算符/指令的类型是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47509869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com