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)
這是否回答你的問題?
添加回答
舉報