用“或”进行分配。在python中 [英] Assignment with "or" in python
本文介绍了用“或”进行分配。在python中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为这样的变量赋值是否被认为是不好的风格?
Is it considered bad style to assign values to variables like this?
x = "foobar" or None
y = some_variable or None
在上面的示例中,x获得值 foobar。
In the above example, x gets the value 'foobar'.
推荐答案
不,这是常见的做法。对于长度比您更长的表达式,它仅被认为是不好的风格。
No, it's a common practice. It's only considered bad style for expressions that are considerably longer than yours.
这篇关于用“或”进行分配。在python中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文