小编am1*_*m17的帖子

调用方法的最佳方法 - Python

我有这两个类,但我想知道在类中调用函数的最佳方法是什么.

我喜欢用这个属性:

class myclass():
    def myfunction(self):
        return self.x + self.y

z = myclass()
z.x = 4
z.y = 3
print z.myfunction()
Run Code Online (Sandbox Code Playgroud)

但我不知道这是否正确.或者我应该使用它而不是最后一个?

class myclass():
    def myfunction(self,x,y):
        return x + y

z = myclass()
print z.myfunction(4,3)
Run Code Online (Sandbox Code Playgroud)

python oop methods class python-2.7

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

标签 统计

class ×1

methods ×1

oop ×1

python ×1

python-2.7 ×1