1 回答
TA贡献1807条经验 获得超9个赞
Python 的结构完全由缩进级别控制:
class circle(object):
def __init__(self, radius=3, color='blue', data_type=np.float64): # default values
self.radius = radius
self.color = color
self.data_type = data_type
# Python assumes this is the end of the __init__ function
# because this next line is at the next higher level
if self.data_type not in [np.float32, np.float64]:
raise ValueError('data_type should be np.float32 or np.float64 only')
# so the above is a fragment that will not run in __init__.
def add_radius(self, r):
self.radius = self.radius + np.ceil(r, dtype=self.data_type)
return(self.radius)
这是否回答你的问题?
添加回答
举报