我最近发现自己经常使用以下模式:
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
但是我不禁觉得设置值然后更改它有点混乱,特别是考虑到在某些用例中很少使用后备值。
有没有更好/更整洁的方法?