Closed anniehuang921 closed 9 years ago
Good Question!
限制三個變數,並且用a=A(1,2,3)取代a=A(x=1,y=2,z=3)
class A(object):
def __init__(self,*args):
assert len(args) <= 3
args_names = ["x","y","z"]
kwargs = dict(zip(args_names[:len(args)],args))
self.__dict__.update(kwargs)
ps.“一”到三個變數都可以呦~~
有沒有更快的? 本來是這樣:
快速設定self.arg=arg?