这个方法比较好:
class DataHolder:
def __init__(self, value=None):
self.value = value
def set(self, value):
self.value = value
return value
def get(self):
return self.value dh = DataHolder()
if dh.set(something()):
# do something with dh.value
elif dh.set(somethingelse()):
# ...
参考链接:
http://*.com/questions/1513436/what-should-i-use-instead-of-assignment-in-an-expression-in-python