正如标题所述,我以困惑为例:
class Point(object):
def __init__(self, x=0.0, y=0.0):
self.x, self.y = x, y
@classmethod
def get_point1(cls, cor): # cor is list with x=1 and y=2
return Point(cor[0], cor[1])
@classmethod
def get_point2(cls, cor):
return cls(cor[0], cor[1])
Run Code Online (Sandbox Code Playgroud)
我很困惑我应该使用哪个(get_point1或get_point2),它们之间有什么区别?
python ×1