1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| class Student(object): score = 100 __math = 10
__slots__ = ('name', '_age', '__sex')
def __init__(self, name, age, sex): self.name = name self._age = age self.__sex = sex
def _getage(self): print("age: ", self._age)
def __getsex(self): print('sex: ', self.__sex)
@staticmethod def func1(): print('staticmethod');
@classmethod def func2(cls, name, age, sex): print(cls.score) cls(name, age, sex).func1()
s = Student('aya', 18, 'girl') print(s.score, s._Student__math) print(s.name, s._age, s._Student__sex) s._getage() s._Student__getsex() s.func1() Student.func1() Student.func2('aya', 18, 'girl')
print(Student.__dict__) print(Student.__doc__) print(Student.__name__) print(Student.__module__) print(Student.__bases__)
|