有一个代码和类'方法有一行:
object.attribute |= variable
Run Code Online (Sandbox Code Playgroud)
我无法理解这意味着什么.我没有在基本Python运算符列表中找到(| =).
假设我们定义一个函数,然后用以下结尾:
def function():
# ...
return result
# To see the result, we need to type:
print(function())
Run Code Online (Sandbox Code Playgroud)
另一种选择是使用以下方式结束函数print:
def function():
# ...
print(result)
# no need of print at the call anymore so
function()
Run Code Online (Sandbox Code Playgroud)
问题:我return是否可以通过声明结束功能,通过function()或不通过?
我的意思是我不关心函数是否保存结果.但是该函数可以有几个不同的结果,即我需要在某个时刻退出循环.主要思想是在屏幕上获得输出.
所以,请让我知道我的变体是否正常,或者它不是'优雅'编码.谢谢!