小编Olg*_*ga 的帖子

Python中的垂直条按位赋值运算符

有一个代码和类'方法有一行:

object.attribute |= variable
Run Code Online (Sandbox Code Playgroud)

我无法理解这意味着什么.我没有在基本Python运算符列表中找到(| =).

python operators python-2.7

17
推荐指数
3
解决办法
1万
查看次数

返回结果并在函数结束时打印它之间的最佳效果是什么?

假设我们定义一个函数,然后用以下结尾:

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()或不通过?
我的意思是我不关心函数是否保存结果.但是该函数可以有几个不同的结果,即我需要在某个时刻退出循环.主要思想是在屏幕上获得输出.
所以,请让我知道我的变体是否正常,或者它不是'优雅'编码.谢谢!

python coding-style function python-3.x

5
推荐指数
2
解决办法
175
查看次数