1. In Python we can import modules to invoke the function inside the module, in a module we can define a lot of functions and variables, but some functions we do not want to be used by others, only want to use inside the module, then we
Can be implemented by _ (underscore) prefixes, such as _abc,_qiuhe, but Python does not enforce restrictions on access to functions or variables, but is a programming habit.
2. In Python, Pip is a package management tool that we use to install third-party software, in general, third-party libraries are registered on the official Python pypi.python.org website, we enter the URL, and then search for the module name we want to download
To download
3. After the download, we will use the PIP tool to install, it is important to note that we download the file under which path, if the path is not accessible by Python will be error, we pass the Import sys module, and then Sys.path, see the Path property
Knowing the path that Python can access, this property returns a list with many elements that represent the path that Python can access, and if the file we downloaded is no longer in this list, we can do it via Sys.path.append ().
Add a path, this method of adding a path is free to run, and will expire after the run is finished.
4. If our other common third-party libraries also have MySQL driver: Mysql-connector-python for scientific Computing NumPy Library: numpy, template tool for generating text jinja2,pillow, etc.
5. Object-oriented programming, the design idea is to abstract out class classes, and then according to the class to write materialized instances
6. The difference between a function in a class and a different function is that the first parameter is always self
7. The property that begins with a double underscore in Python is a private property that cannot be modified externally, and only the intrinsic function can be modified, with the double underscore beginning and the double underscore ending we become special attributes that are directly accessible to the special attribute.
8. Inside the class, we can privatize the attribute, preceded by two underscores, so that once an instance is materialized, the instance cannot be given the instance name. Property =:, which modifies the value of the property and cannot be accessed in this form
, because properties are privatized, if you want to access we can define functions within a class, get_ properties (), set_ properties (), call these functions from an instance to display the properties of an instance, or modify the properties of an instance
9. In an inheritance relationship, if the data type of an instance is a subclass, its data type can also be considered a parent class. But not in the opposite way.
10. Class is also a data type, similar to Int,str,list, when defining a function, if we need to specify the data type of the argument, then our parameter name should be this data type, Def a (Int,list, class name), so that the value
, the first must be shaping, the second must be a list, and the third must be the specified class name.
11. The polymorphism of the class, when the parameter name inside a function is a class name, if the passed argument is a subclass of the class, then the function will treat the class as if it were their parent class, which is the polymorphism of the class
12.python is a dynamic language, the parameter name is a class name, because of the dynamic, so there is a duck type in Python, that is, whether you are a duck, as long as you walk like a duck, then Python thinks you are a duck, so, in the class to pass in the argument
As long as there are functions involved in the body of the function, it can be called, not the subclass of the parameter class.
13.power (x, Y, z) represents the z-balance of the ×, where z is optional and x, Y is required
14. Determine what type of an object we can use the type () function to determine whether an object is a type that can be isinstance (,), and use the function dir (object name) to get all the properties (variables) and methods (functions) of this object.
GetAttr (object name, ' property name '), from this function to get the value of this property, Hasattr (object name, ' attribute name '), to determine whether this object belongs to this property, SetAttr (object name, ' property name ', value), will
This property in this object is assigned a value
15. In a class, if you define a property that belongs to a class, then when you create the instance, it will also have all the properties of that class.
16.__SLOTS__ special variables, used in the class, to restrict which attributes can be added to instances created by the class, if an attribute is added that is not here, an error is given, __slots__= (' property name ', ' property name ',...), if an instance created with a subclass
If there is no such special attribute in the subclass, then the subclass does not inherit this special attribute of the parent class, and if so, the limit of the instance is the subclass plus the parent class.
17. The difference between a function that is bound to a class and a function defined in a class is that the bound function is bound only to the class, and the function is called at the same time for more than one instance, returning the most of the result of the call, that is, overwriting, for the internally defined function
is equivalent to binding to each instance, and then each time it is called, it returns the result of the respective invocation.
18. The method defined in the class is generally a dynamic method (if not forced static), this dynamic method, the class is not directly called, must be bound to an instance, through an instance to invoke, defined in the class properties are the same, is static
, but the instance is accessible, but the property belongs to the class only, not to the instance, and if the instance adds a property that is the same as the Class property, the instance can change the property value.
19. Multiple inheritance refers to a subclass that can inherit multiple parent classes, so the subclass can have multiple properties and methods of the parent class
20.A.__LEN__ is the equivalent of Len (a)
21. By writing the __iter__ (), __next__ () function in the class to turn the class into an iterative object, the __iter__ () function turns the class into an iterative object, and __next__ () takes a value out of it, in fact for. In ... The loop inside the statement
The iterated value of a variable is taken from one of the next functions,
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Python rookie Diary 5