zoukankan      html  css  js  c++  java
  • class definition in python

    class define in python:

    class AddressBookEntry(object):
        version = 0.1
        def __init__(self, name, phone):
            self.name = name
            self.phone = phone
        def update_phone(self, phone):
            self.phone = phone

    subclass of the class:

    class EmployeeAddressBookEntry(AddressBookEntry):
        def __init__(self, name, phone, id, social):
            AddressBookEntry.__init__(self, name, phone)
            self.empid = id
            self.ssn = social

    The object in the brackets is the class which we inherit from. 

     

    dynamic instance attributes, those that are not declared anywhere in the class definition, yet can be created “on the fly.”
    We can use this like this:

    Bob = AddressBookEntry('Bob', '2b7474748')

    Bob.JJ = None

    This inner class is a real Python class, but is only visible to instances of the MyClass class.
    class MyClass(object):
        class InnerClass:
            pass

  • 相关阅读:
    linux常用命令
    PHP 魔术方法浅谈
    PHP常用的设计模式
    浅谈Restful
    进程,线程与协程的区别
    http与https的
    get与post的区别
    php连接数据库的两种方式
    DRF框架基本组件之过滤,搜索,排序
    DRF-JWT用户认证
  • 原文地址:https://www.cnblogs.com/henyihanwobushi/p/2676496.html
Copyright © 2011-2022 走看看