常见的写法:
def __init__(self, x, y, z):
...
self.x = x
self.y = y
self.z = z
...
可以简写成如下:
class A:
def __init__(self, **kwargs):
for key in kwargs:
setattr(self, key, kwargs[key])
常见的写法:
def __init__(self, x, y, z):
...
self.x = x
self.y = y
self.z = z
...
可以简写成如下:
class A:
def __init__(self, **kwargs):
for key in kwargs:
setattr(self, key, kwargs[key])
Copyright © 2015 Powered by MWeb, Theme used GitHub CSS.