Tag: Blank relative to module reload includes att modifier character border
Before entering object-oriented programming, we want to make a collation of Python's common built-in functions, referring to the official website.
Common built-in functions
Chr (number) |
Returns the ASCII code for a given number of characters |
Ord (char) |
Returns the ASCII value of an order character (a string of length 1 or a Unicode string) |
All (iterable) |
Returns true if all iterable elements are true, otherwise false |
Any (iterable) |
Returns true if any of the iterable elements are true, otherwise false |
Callable (object) |
Checks whether an object can be called |
Dir ([Object]) |
Selectively list (most) attributes of a given object |
Help ([Object]) |
Call the built-in Help system, or print help for a given object |
Reload (module) |
Reload into an already loaded module and return it |
Repr (object) |
Returns a String representing an object, typically used as an eval parameter |
Eval (string[, globals[, locals]) |
To evaluate a string containing an expression |
Input ([prompt]) |
Equivalent to eval (raw_input (Prompt) |
Raw_input ([prompt]) |
Returns the data entered by the user as a string, optionally using the given prompt prompt |
Str (object) |
Returns a well-formatted string representing the object of the given objects |
Type (object) |
Returns the type of the given object |
Object-Oriented Programming
Object-oriented is a programming method, which is relative to process-oriented, classify and encapsulate functions.
Initial knowledge of object-oriented concept |
Concept |
Description |
Example |
class |
Some things in the real world are encapsulated in abstraction. Start with the keyword class, followed by the class name and colon. |
class person: name = ' Lucy ' def setage (self,age): self.age = Age |
Object |
A class defines an instance of an object that includes properties and methods. Objects are divided into class objects, instance objects |
|
Class object |
Once the class definition is complete, a global class object is created, and the properties and methods in the class can be accessed through the class object. |
Person Class object |
Instance Object |
An instance object is an instantiation of a class that can instantiate multiple |
p = person () instance object |
Property |
Describe what the object is or what it can do. |
|
Class properties |
The properties common to all instance objects of a class property, outside the class, can be defined or modified by class objects, within a class, only in class methods. |
name = ' Lucy ' class property Person.country = ' China ' defined by class object |
Instance Properties |
The properties of an instance object that, when conflicting with a class property, mask the Class property. |
P.country = ' China ' is defined by an instance object
|
Private properties |
Starts with a double underscore and cannot be accessed directly outside of the class |
__name = ' Lucy ' |
Function |
Code blocks for specific functions for easy reuse |
def setage (age): return age |
Method |
Method is the same as function function, written in the class, with the object in conjunction with |
def setage (self,age): Self.age = Age |
Class method |
Methods with @classmethod modifiers and must have a CLS parameter, which can be accessed through instance objects and class objects |
@classmethod def setage (cls,age): Cls.age = Age |
Instance method |
Methods with self, accessible only through instance objects |
def setage (self,age): Self.age = Age |
Static methods |
Methods with @staticmethod modifiers that can only be accessed through class objects |
@staticmethod def setage (age): return age |
Common built-in methods
Built-in methods for classes |
Built-in Method name |
Description |
__init__ (self,...) |
Initializes an object that is called when a new object is created |
__del__ (self) |
Frees the object to be called before the object is deleted |
__new__ (CLS,*ARGS,**KWD) |
The build action of the instance |
__str__ (self) |
Called when the print statement is used |
__call__ (Self,*args) |
To call an instance object as a function |
__GETATTR__ (S,name) |
Gets the value of the property |
__SETATTR__ (S,name,value) |
Set the value of a property |
__DELATTR__ (S,name) |
Delete the value of an attribute |
A review of basic knowledge--object-oriented programming