1.self作为一个参数,其实就可以当做一个对象来看,可以用self在类函数里面调用类里面的其他函数
2.类属性和对象属性是不一样的,如下面的B=[]就是类属性,一个对象改变了它,类的其他对象的该属性也会改变,init里面的属性才是自己的
import os
import collections
import math
import sys
class person(object):
B=[]
def __init__(self, name, age):
self.A = []
self.name = name
self.age = age
def speak(self):
print("我的名字是:" + self.name)
print("我的年龄是:" + self.age)
I = person("xdn", "21")
I.speak()
I.A.append(3)
I.B.append(4)
print(I.A)
print(I.B)
P = person("xdn", "21")
print(P.A)
print(P.B)
结果: