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
嗎?