Function
def function name (formal parameter): parameter not defined in front, local variable
Parameters
Must parameter must be passed in the correct order
Keyword parameters can be added to the keyword without the need for proper sequence of arguments
Default parameter If no arguments are passed, the default value is used
Indefinite length parameter
class = = = Large Hump
There are two types of definition classes: Classic car and modern class car (Object)
Object name = Class name ()
If you need to modify the class properties outside of the class, you must refer to the class object and then modify it.
Attribute naming method, if you add 2 underscore ' __ ' before the property name, it indicates that the property is a private property.
Otherwise, the public attribute (the same way, with 2 underscores in front of the method name indicates that the method is private,
Otherwise, it is public).
Private properties that cannot be accessed directly through the object, but can be accessed by means of a method
Private method that cannot be accessed directly by the object
Private properties, methods, are not inherited by the quilt class, and cannot be accessed
In general, private properties, methods are not disclosed, often used to do internal things, play a safe role
Polymorphic: When the type of the definition is different from the runtime type, it becomes polymorphic at this time
Class properties and Instance properties
If referenced by an instance object, it produces an instance property of the same name, which modifies the instance property
Does not affect the Class property, and then if the property of the name is referenced by the instance object,
Instance properties force the masking of class properties, that is, instance properties, unless the instance property is deleted.
Describe
Class Property private) class variable
Instance property private) member variable
Static Methods and Class methods
A class method is a method owned by a class object The first argument must be a class object CLS representation
Ability to access through instance objects and class objects
After the class method has been modified on the Class property, access through the class object and the instance object has changed
It can be seen from the definition of the class method and the instance method and the static method.
The first parameter of a class method is the class object CLS, so the properties and methods of the class object must be referenced by the CLS.
The first argument to the instance method is the instance object self, which is referred to by self as a possible class property or an instance attribute (this requires a specific analysis)
In the case of class and instance properties with the same name, however, the instance property has a higher precedence.
There is no need to define additional parameters in a static method, so referencing a class property in a static method must be referenced by a class object
Function Import Module
The module is either a package, but it cannot be a class, function, or variable name.
Module: A file containing all the functions and variables you define, which can be introduced by other programs,
Importing the entire module can only be imported once
Import support
Part of the Import module
From ... import
From ... import* import all (function, variable) content except for the beginning of the underscore __
Using this method overrides the function defined by itself
You can use __name__ = = ' __main__ ' to indicate the use of the module itself
Package: A form of management module namespace with "Point module name"
Example: A module A.B represents a sub-module B of a package
Exception handling
Try ———— except (may have multiple, handle different exceptions)
The TRY clause is executed first, and if there is no exception, the EXCEPT clause is not executed
However, if there is an exception during execution. And the exception that follows except then executes the statement after the except statement executes the last try
If there is no match, then the exception is passed to the previous layer of try
Throw exception
Raise
Object oriented
Class: Used to describe a collection of objects that have the same properties and methods. It defines the properties and methods that are common to each object in the collection. An object is an instance of a class.
Class variables: Class variables are common throughout the instantiated object. Class variables are defined in the class and outside the body of the function. Class variables are not typically used as instance variables.
Data members: Class variables or instance variables are used to manipulate the data related to the class and its instance objects.
Method overrides: If the method inherited from the parent class does not meet the requirements of the subclass, it can be overridden, which is called the override of the method, also known as the override of the method.
Instance variable: A variable defined in a method that acts only on the class of the current instance.
Inheritance: A derived class (derived class) that inherits the fields and methods of the base class. Inheritance also allows the object of a derived class to be treated as a base class object. For example, there is a design where an object of type dog is derived from the animal class, which is the analog "is a (is-a)" Relationship (example, dog is a animal).
Instantiation: Creates an instance of a class, the concrete object of the class.
Method: A function defined in a class.
Object: an instance of a data structure defined by a class. Object consists of two data members (class variables and instance variables) and methods
The class method must contain the parameter self, which is the first argument, and self represents an instance of the class.
Supports multiple inheritance: The default is to invoke the method of the parent class in parentheses before
The private property of the __private_attrs class
Private method of the __private_methods class
Functions in Python