python类创建对象的公有属性和私有属性
>>> bart = Student('Bart Simpson', 59)>>> lisa = Student('Lisa Simpson', 87)>>> bart.age = 8>>> bart.age8>>> lisa.ageTraceback (most recent call last):File "<stdin>", line 1, in <module>AttributeError: 'Student' object has no attribute 'age'在类里面定义的变量是共有的,创建的每个对象都会继承在类外面定义的变量是私有的,只有自己这个类拥有,别的没有
页:
[1]