Python object-oriented programming foundation

A, classes and objects

  Simply put, the class is a blueprint and template objects, and objects are instances of classes. Although this explanation was sort of like the concept in the interpretation of the concept, but at least we can see from this statement, the class is an abstract concept, but the object is a specific thing. In object-oriented programming world, everything is an object, the object has attributes and behavior of each object is unique, and the object must belong to a certain category (type). When we put the static characteristic (property) has a lot of common features of objects and dynamic characteristics (behavior) are extracted, you can define a named "class" thing.

Second, the definition of class

  You may be used in Python class keyword to define classes and methods defined in the class, so that you can describe the dynamic characteristics of the object, as follows:

  

  Description: write functions in the class, we usually call a method (the object), the object of these methods is that a message may be received

 Third, create and use objects

  When we created a class, you can create objects in the following way and give the object a message

  

Fourth, access to visibility problems

  In Python, access the properties and methods of only two, that is, public and private, if you want the property is private property in the name to be used as two underscores beginning, the following code can verify this.

  

  However, Python does not guarantee strict privacy private property or method from the grammar, it just gives private properties and methods of a change of name to "hinder" access to them, in fact, if you know the rules can still change the name of access to them, the following code can verify this.

  

 

Guess you like

Origin www.cnblogs.com/xsnblog/p/11304525.html
Recommended