作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么这段代码会这样工作?
x = 3
print(dir()) #output indicates that x is defined in the global scope
del (x)
print(dir()) #output indicates that x is not defined in the global scope
我的理解是,del
是Python中的关键字,del
后面的应该是一个名字。 (name)
不是名称。为什么该示例似乎表明 del (name)
与 del name
的作用相同?
最佳答案
del
statement 的定义是:
del_stmt ::= "del" target_list
并根据 target_list
的定义:
target_list ::= target ("," target)* [","]
target ::= identifier
| "(" target_list ")"
| "[" [target_list] "]"
| ...
您可以看到允许在目标列表两边使用括号。
例如,如果您定义x,y = 1,2
,则所有这些都是允许的并且具有相同的效果:
del x,y
del (x,y)
del (x),[y]
del [x,(y)]
del ([x], (y))
关于python - 为什么变量名两边带括号的 del(x) 有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39028249/
我目前正在编写一份报告,其中包含从 Web 服务注入(inject)的数据。该网络服务向其发送“双重?”允许空值。在报告中,它显示返回的值,这些值稍后用于对数字进行求和和平均。我的问题在于显示值的表达
我是一名优秀的程序员,十分优秀!