我最近经常使用以下模式:
x = 3
if this:
this.process()
if this.something:
x = this.a_value
我不想做这个:
if this and (this.process() or True) and this.someting:
x = this.a_value
else:
x = 3
或者这样:
if this:
this.process()
if this.something:
x = this.a_value
else:
x = 3
else:
x = 3
但我不禁觉得,先设定一个值然后再去改变它有些混乱,尤其是在某些情况下很少使用备用值的时候。
是否有更好/更整洁的方法?