62复习Python_OOP
class Student:
pass
class Person():
pass
def main():
print(Student) # <class '__main__.Student'>
student `1``111111111111 = Student()
print(student1) # <__main__.Student object at 0x0000018AB6F89320>
print(id(student1)) # 1695286858528
print(hex(id(student1))) # 0x18ab6f89320
print(isinstance(student1, Student)) # True
print(isinstance(student1, Person)) # False
if __name__ == '__main__':
print(type(Student)) # <class 'type'>
print(type(Person)) # <class 'type'>
print(isinstance(Student, type)) # True
main()
类变量
- 取得类变量的值

在Java中属于用static类似的
- 设置类变量的指
直接赋值和使用setattr()函数

- 删除类变量

- 类变量的存储

私有属性与函数
python中 _相当于java的保护 __相当于私有
如果需要在外部使用 对象._类名__实例属性/方法 (python存在类属性 和 实例属性)

类方法和静态方法
类方法

静态方法

常用的特殊方法

str

repr

eq

hash

bool

del

property类


@property装饰器


本文来自博客园,作者:__username,转载请注明原文链接:https://www.cnblogs.com/code3/p/17081035.html

浙公网安备 33010602011771号