Code: Alles auswählen
>>> cond = True
>>> a = 1
>>> b = 2
>>> cond and a or b
1
>>> cond = False
>>> cond and a or b
2
>>> a = 0
>>> cond = True
>>> cond and a or b
2
Code: Alles auswählen
>>> cond = True
>>> a = 1
>>> b = 2
>>> cond and a or b
1
>>> cond = False
>>> cond and a or b
2
>>> a = 0
>>> cond = True
>>> cond and a or b
2
Code: Alles auswählen
class A(object):
def __init__(self, a=None):
self.a = a or []
class B(object):
def __init__(self, a=None):
self.a = a if a is not None else []
def main():
for c in [A, B]:
xs = list()
obj = c(xs)
xs.append(42)
print xs == obj.a
if __name__ == '__main__':
main()