0
我是Python新手(来自C#),试图弄清楚OOP如何在这里工作。 从开始就开始尝试实现Vector
类。 我想要有在Vector
类中定义的基向量(i,j,k)。 在C#中,我能做到这样的:class vs static methods
public class Vector
{
// fields...
public Vector(int[] array){
//...
}
public static Vector i(){
return new Vector(new int[1, 0, 0]);
}
}
探索的Python我发现2种方式如何实现这一点:无论是使用@classmethod
或@staticmethod
:
class Vector:
def __init__(array):
#...
@classmethod
def i(self):
return Vector([1, 0, 0])
因为我并不需要有访问课堂内的任何信息,我真的应该使用@classmethod
吗?