我在 github 链接中看到下面的语句,想知道这个条件是如何执行的。 or 的右侧表达式检查条件,但左侧更像是一个赋值语句。
shape.fill = shape.selected or shape == self.hShape
最佳答案
在此上下文中,shape.selected
是一个 bool 属性,因此代码等同于:
if shape.selected:
shape.fill = shape.selected
else:
shape.fill = shape == self.hShape
这有帮助吗?
关于带有 or 语句的 python 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51162074/