小编zha*_*gqy的帖子

我应该使用类名还是 `cls` 参数来构造一个实例?

正如标题所述,我以困惑为例:

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_point1get_point2),它们之间有什么区别?

python

2
推荐指数
1
解决办法
902
查看次数

标签 统计

python ×1