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装饰器

posted @ 2023-01-31 22:22  __username  阅读(5)  评论(0编辑  收藏  举报

本文作者:DIVMonster

本文链接:https://www.cnblogs.com/guangzan/p/12886111.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。