基本概念
child::python self参数
语法
class X(Y) :
创建一个名为 X 并继承自 Y 的类。
(“Make a class named X that is-a Y.”)
class X(object): def __init__(self, J)
类 X 有一个带有 self 和 J 参数的 [[python init()构造方法详解|init 函数]]。
(“class X has-a init that takes self and J parameters.”)
class X(object): def M(self, J):
类 X 有一个带有 self 和 J 参数的 M 函数。
(“class X has-a function named M that takes self and J parameters.”)
foo = X():
设 foo 为类 X 的一个实例。
(“Set foo to an instance of class X.”)
foo.M(J)
从 foo 那里获取 M 函数,并用 self 和 J 参数来调用它。
(“From foo, get the M function, and call it with parameters self, J.”)
foo.K = Q
从 foo 那里获取 K 属性,并设它为 Q。
(“From foo, get the K attribute, and set it to Q.”)