什么是在Python中使用多个构造函数的干净的、pythonic的方法?
__init__
Cheese
number_of_holes
parmesan = Cheese(num_holes = 15)
number_of_holes
gouda = Cheese()
class Cheese(): def __init__(self, num_holes = 0): if (num_holes == 0): # randomize number_of_holes else: number_of_holes = num_holes
相关分类