问题描述
我正在解密别人的代码,并且看到以下内容:
I am deciphering someone else's code and I see the following:
def get_set_string(set_):
if PY3:
return str(set_)
else:
return str(set_)
变量后的下划线是什么意思,还是仅仅是变量名称的一部分,什么都没有?
Does the underscore AFTER the variable mean anything or is this just a part of the variable's name and means nothing?
推荐答案
没有语义与结尾的下划线相关联.根据 PEP 8
的指导, Python,强烈建议用户使用结尾的下划线,以免与Python关键字和/或Python内置插件冲突:
No semantics are associated with a trailing underscore. According to PEP 8
, the style guide for Python, users are urged to use trailing underscores in order to not conflict with Python keywords and/or Python built-ins:
Tkinter.Toplevel(master, class_='ClassName')
使用set_
表示集的内置名称,即set
,不会在函数调用期间被遮盖并丢失其已知引用.
Using set_
means that the built-in name for sets, i.e set
, won't get shadowed and lose its known reference during the function call.
这篇关于Python中变量名后的下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!