草庐IT

python - 单下划线 "_"是 Python 中的内置变量吗?

我不明白这个单下划线是什么意思。它是一个神奇的变量吗?我在locals()和globals()中看不到它。>>>'abc''abc'>>>len(_)3>>> 最佳答案 在标准PythonREPL中,_代表最后一个返回值——在你调用len(_)的地方,_是值'abc'。例如:>>>1010>>>_10>>>_+515>>>_+520这由sys.displayhook处理,_变量进入builtins带有int和sum之类的命名空间,这就是为什么您在globals()中找不到它的原因。请注意,Python脚本中没有这样的功能。在脚本中,

python - 单下划线 "_"是 Python 中的内置变量吗?

我不明白这个单下划线是什么意思。它是一个神奇的变量吗?我在locals()和globals()中看不到它。>>>'abc''abc'>>>len(_)3>>> 最佳答案 在标准PythonREPL中,_代表最后一个返回值——在你调用len(_)的地方,_是值'abc'。例如:>>>1010>>>_10>>>_+515>>>_+520这由sys.displayhook处理,_变量进入builtins带有int和sum之类的命名空间,这就是为什么您在globals()中找不到它的原因。请注意,Python脚本中没有这样的功能。在脚本中,

python - c 下划线表达式 `c_` 究竟做了什么?

这似乎是某种水平连接,但我在网上找不到任何文档。这是一个最小的工作示例:In[1]:fromnumpyimportc_In[2]:a=ones(4)In[3]:b=zeros((4,10))In[4]:c_[a,b]Out[4]:array([[1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.],[1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.],[1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.],[1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]]) 最佳答案

python - c 下划线表达式 `c_` 究竟做了什么?

这似乎是某种水平连接,但我在网上找不到任何文档。这是一个最小的工作示例:In[1]:fromnumpyimportc_In[2]:a=ones(4)In[3]:b=zeros((4,10))In[4]:c_[a,b]Out[4]:array([[1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.],[1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.],[1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.],[1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]]) 最佳答案

python - 前后下划线的python属性有什么区别

这个问题在这里已经有了答案:Whatisthemeaningofsingleanddoubleunderscorebeforeanobjectname?(18个回答)Differencebetween"__method__"and"method"[duplicate](7个回答)关闭3个月前。我想知道Python中这些有什么区别?self._var1self._var1_self.__var1self.__var1__ 最佳答案 作为起点,您可能会发现PEP8-StyleGuideForPythonCode中的这句话很有帮助:Ina

python - 前后下划线的python属性有什么区别

这个问题在这里已经有了答案:Whatisthemeaningofsingleanddoubleunderscorebeforeanobjectname?(18个回答)Differencebetween"__method__"and"method"[duplicate](7个回答)关闭3个月前。我想知道Python中这些有什么区别?self._var1self._var1_self.__var1self.__var1__ 最佳答案 作为起点,您可能会发现PEP8-StyleGuideForPythonCode中的这句话很有帮助:Ina

python - 在 Python 赋值运算符中使用逗号和下划线的含义?

这个问题在这里已经有了答案:Whatisthepurposeofthesingleunderscore"_"variableinPython?(5个回答)关闭4个月前。阅读PeterNorvig的SolvingEverySudokuPuzzleessay,遇到了几个没见过的Python习语。我知道一个函数可以返回一个元组/值列表,在这种情况下,您可以为结果分配多个变量,例如deff():return1,2a,b=f()但是下面每一个的含义是什么?d2,=values[s]##values[s]isastringandatthispointlen(values[s])is1如果len(v

python - 在 Python 赋值运算符中使用逗号和下划线的含义?

这个问题在这里已经有了答案:Whatisthepurposeofthesingleunderscore"_"variableinPython?(5个回答)关闭4个月前。阅读PeterNorvig的SolvingEverySudokuPuzzleessay,遇到了几个没见过的Python习语。我知道一个函数可以返回一个元组/值列表,在这种情况下,您可以为结果分配多个变量,例如deff():return1,2a,b=f()但是下面每一个的含义是什么?d2,=values[s]##values[s]isastringandatthispointlen(values[s])is1如果len(v

python - 为什么文件名的下划线比连字符更好?

来自BuildingSkillsinPython:Afilenamelikeexercise_1.pyisbetterthanthenameexercise-1.py.Wecanrunbothprogramsequallywellfromthecommandline,butthenamewiththehyphenlimitsourabilitytowritelargerandmoresophisticatedprograms.这是为什么? 最佳答案 这里的问题是使用hyphen-minus导入文件(默认键盘键-;U+002D)在他们

python - 为什么文件名的下划线比连字符更好?

来自BuildingSkillsinPython:Afilenamelikeexercise_1.pyisbetterthanthenameexercise-1.py.Wecanrunbothprogramsequallywellfromthecommandline,butthenamewiththehyphenlimitsourabilitytowritelargerandmoresophisticatedprograms.这是为什么? 最佳答案 这里的问题是使用hyphen-minus导入文件(默认键盘键-;U+002D)在他们