The module is like a dictionary
A dictionary is the only mapping relationship in Python that uses one thing to correspond to another, the so-called Key->value.
The module contains variables and functions that you can import, and you can manipulate access to variables and functions with dots (·).
Remember to ' get the concept of y from X '.
They are similar, except for the grammatical differences.
1. In other words, there is a common pattern in Python:
(1) A container with a key =value
(2) Retrieving data from the container via key
Different points:
In the dictionary, key is a string, written as [key], and in the module as. Key, the rest of the place is identical.
Classes are like modules
You can think of a module as a special dictionary of Python, and then you can access it using the dot (*) operator.
Class is to organize a series of functions and data and place them in a container, and you can also access them using the dot (*) operator.
Classes can be used to create a number of categories similar to the base class, while the module one imports the entire project with only one module
Objects are like imported
If the class is like a module, then there should also be an import-like concept. In a class, this concept is called instantiation, and when a class is instantiated, it gets the object of a class.
Create a class;
Class MyStuff (object):
def __init__ (self):
SELF.A = ' How is it? '
def apple (self):
Print ("I am classy apple")
b = MyStuff () #类的实例化
B.apple () #调用类的方法
Print b.a# properties of the printing class
Analyzing the instantiation of a class this sentence actually python has done a lot of things inside of us:
Python Lookup MyStuff () class confirmation is defined
--->python create a new object that contains all the functions defined in MyStuff ()
--->python find out if the __init__ () function is defined in the MyStuff () class, initialize the empty object if there is one
---the __init__ () method in the >mystuff () Class A self parameter, which is the empty object we created, which can be set on the variable
---> Set arguments to SELF.A (empty object) variables, initialize this object
---> Until now python can use this empty object and assign it to variable B.
Stupid way to learn Python's modules, classes, objects