Class definition format :

class CLASSNAME( Parent class 1, Parent class 2, Parent class 3):

__A  = 0     ## Private property , Two _ start , Only functions in this class can access

B = 0 ## Public attribute

def Function name (self):

self.__A = ... # Access private property name

self.B = ... # Access to the public property name


1、 When defining a function , Be sure to have self This parameter , And be sure to put it in the first place

2、 When defining private functions , Function names are the same as private properties , Two, please _ start

3、 The inherited parent class can be more than one , Multiple parent classes have the same function , If other functions want to call this function , It will search from left to right , Only the first parent class with the function is accessed

4、 Functions in the parent class can be overridden in the subclass

5、 If you want to instantiate or inherit classes from other modules , Must use first import Import the module , Then instantiate or inherit

6、 The proprietary methods in the class are as follows :

  1   __init__ Constructors , Call... When generating an object
  2 __del__ Destructor , Use... When releasing objects
  3 __setitem__ Assign values according to the index
  4 __repr__ Print , transformation
  5 __getitem__ Get values by index
  6 __len__ Get the length
  7 __cmp__ Comparison operations
  8 __add__ Add operation
  9 __sub__ Subtraction operation
  10 __mull__ Multiplication
  11 __div__ In addition to the operation
  12 __mod__ The remainder
  13 __pow__ Multiplication
  14 __call__ Function call

python—— Class

  1. Python Class super() and __init__() The relationship between

    Python Class super() and __init__() The relationship between 1. Single inheritance super() and __init__() The functions implemented are similar class Base(object): def __init__(sel ...

  2. LightMysql: For ease of operation MySQL And packaged Python class

    Link to the original text : mysqldb yes Python ...

  3. python Class properties and methods

    Python Class properties and methods label ( The blank space to separate ): Python Python Access restrictions Python Support for object-oriented , The permission control of attribute is realized by attribute name , If an attribute starts with a double underline (__), The attribute cannot be excluded ...

  4. python Class and singleton pattern

    python There are also object-oriented ideas , Then everything is the object python Define a class in : class student: count = 0         books = [] def __init__(self ...

  5. Python Class characteristics (1): Constructors and methods

    Python in , Class characteristics : #encoding:utf-8 class Parent(object): x=1 #x yes Parent Attributes of a class ( Field ) def __init__(self): print ...

  6. Python Class properties , Instance attributes

    1.Python Class data properties : Variables defined inside a class but outside a function , They are all static . # A very simple piece of code , But there was a lot of reaction >>> class A(): a=1 # There is an attribute in a class a > ...

  7. python Class and its methods

    python Class and its methods One . Introduce stay Python in , Object oriented programming has two main themes , Class and class instance : Classes and instances are related to each other : A class is the definition of an object , And the example is " Real objects ", It's stored in the class ...

  8. python Definition and use of classes

    python The declaration of a class in uses keywords class, You can provide an optional parent class or base class , If there is no suitable base class , Then use object As the base class . Define format : class Class name (object): " Class ...

  9. Python Class discussion

    Our next discussion is based on Python3, What I actually tested was Python3.2,Python3 And Python2 Changed the type of class function 1, Class definition syntax   Python Class is defined with keywords class start , A class definition example ...

  10. python - Class member modifier

    stay java,c# Class member modifiers include , public . private . Assembly available . The protected . about python Come on , There are only two member modifiers : Members of the public , Private member Who is the member modifier for ? Of course, it's the grooming . that python The formation of a class ...

Random recommendation

  1. 【jq】c# Zero basic learning road (2) Loops and branching

    One . Loop statement 1).do { // The loop body , Run it first . } while (true); 2). while (true) { // The loop body } 3). for (int i = 0; i < le ...

  2. sql join Optimize

    Item query list , A new table needs to be associated , So I asked the group to change sql sentence , When you enter the list query again, the query time will be doubled . That guy has been looking for a long time without finding out why . So I opened the code to see , There is a lot of data associated with a table , With left jo ...

  3. HTML5 Examples of judging whether a device is online or offline and monitoring changes in network state

    After testing android ipad The default browser supports , use appcan Encapsulated web pages also support This article is original. , Reprint please explain the source <!doctype html> <html> <head> ...

  4. easyui in jquery Repeat the question (tab Memory leak problem )

    I've had a serious test today easyui Some compatibility issues with , Found in ie9 ie10 On first load , The following will appear bug. As shown in the figure : Take a serious look , I think it's the problem of script repeated references , I am using iframe The pattern of the framework . After logging into the system , table ...

  5. HDU1542--Atlantis( Scan line )

    to N The coordinates of the ends of a rectangle , Find the covering area of the rectangle and . The principle is simple , Scan from left to right , The segment tree records the length of the vertical overlay . Interval update . Because the coordinates are real and very large , So we need to discretize . WA+RE+CE+MLE+... There were more than 20 mistakes . ...

  6. poj 2408 Anagram Groups(hash)

    id=2408" target="_blank" style=""> Topic link :poj 2408 Anagram Groups The main idea of the topic : Given a number of ...

  7. [SQL Basic course ] 2-3 Logical operators

    [SQL Basic course ] 2-3 Logical operators NOT AND OR priority ( ) Change priorities AND Priority over OR NULL Three valued logic is introduced

  8. java details , You can't imagine

    One . The construction method constructs a new object every time , There is no problem that multiple threads read and write properties in the same object at the same time , So there's no need to synchronize . If a method in the parent class uses  synchronized keyword , This method is also covered in the subclass , By default ...

  9. WebGL Examples of multi model illumination synthesis

    Original address :WebGL Examples of multi model illumination synthesis WebGL Is a very close to the bottom of the hardware rasterization API, From very similar C/C++ Style API You can see the call mode , Used to high-level language, we will feel very unfriendly , I feel special ...

  10. .NET Core Development log ——Runtime IDentifier

    .NET Core For tradition .NET It's a new platform that developers are familiar with and unfamiliar with , So sometimes it's normal to meet unexpected things . Just be patient , Check more information , Try to find out why , It's a meaningful experience . For example, when building a minimalist ...