zoukankan      html  css  js  c++  java
  • python对象

    对象 = 属性+方法 面向对象特征(封装继承多态)

    class Turtle:   #python中类名首字母大写
        
        #属性
        color = ’green'
    
        #方法
        def climb(self):
            print('i am climb')
    
    class MyList(list):  //继承 子类覆盖父类同名方法
      def __init__(self):
        #list.__init__(self)
        super().__init__()
    pass

    不同对象对同一动作有不同反应  

    魔法方法__:

    __init__(self):构造方法
        class A(B):
            def __init__(self):
                super().__init__()
    __new__(cls):继承不可变类型时有用
        class CapStr(str):
            def __new__(cls, string):
                string = string.upper()
                return str.__new__(cls, string)
    __del__(self):析构
        del c

    公有 name 私有__name

    组合:把没有实现关系的多个类放在一个类中

    类,类对象,实例对象

    常用BIF

      issubclass(A,B)

      issubclass(A,object)

      isinstance(a,A)

      hasattr(a,'x')

      property()

      

  • 相关阅读:
    MS-data
    Lammps命令与in文件
    VMD建模得到模型
    VMD-合并模型与生成data文件
    VMD-水溶液中注入离子
    水分子模型
    1.MD相关概念
    Python7
    python6
    python5
  • 原文地址:https://www.cnblogs.com/echoshao/p/6535030.html
Copyright © 2011-2022 走看看