zoukankan      html  css  js  c++  java
  • 类、对象常用方法、属性

     '__module__',    #属性 表示当前操作的对象在哪个模块
     '__init__',      #方法 实例化对象是,初始化对象的属性
     '__setattr__',   #方法 给对象增加或者修改属性时执行
     '__delattr__',   #方法 删除对象时执行
     '__dict__',      #属性 类的静态函数、类函数、普通函数、全局变量以及一些内置的属性都是放在类__dict__里的; 对象的__dict__中存储了一些self.xxx的一些东西
     '__weakref__',
     '__doc__',       #属性 注释  
     '__repr__',
     '__hash__',
     '__str__', 
     '__getattribute__', 
     '__lt__', 
     '__le__', 
     '__eq__', 
     '__ne__', 
     '__gt__', 
     '__ge__', 
     '__new__', 
     '__reduce_ex__', 
     '__reduce__', 
     '__subclasshook__', 
     '__init_subclass__', 
     '__format__', 
     '__sizeof__',   #方法 对象在内存中的大小
     '__dir__',      #属性 对象所有属性及方法的名字
     '__class__'
    class Persion:
        """
        aaaaaa
        """
        def __init__(self,name,age,sex):
            self.name=name
            self.age=age
            self.sex=sex
        def __setattr__(self, key, value):
            # self.key=value
            self.__dict__[key]=value
            print("{}:{}".format(key,value))
        def __delattr__(self, item):
            print("delete  {}".format(item))
    
    man=Persion("zh",18,"male")
    man.love="runing"
    # print(Persion.__dict__)
    # print(man.__dict__)
    print(man.__dir__())
    # print(man.__sizeof__())
    print(man.__doc__)
    print(man.__module__)
    print(man.__weakref__)
  • 相关阅读:
    python函数嵌套的实用技术
    windows10 装linux子系统
    彻底测试全部拷贝list相关操作的区别python
    c语言学习
    Pickling
    Filenames and paths
    Format operator
    Reading and writing
    Persistence
    Automation testing tool comparison
  • 原文地址:https://www.cnblogs.com/Hale-wang/p/14465374.html
Copyright © 2011-2022 走看看