
撷取浓厚兴趣,散播欢乐,快速增长所见所闻,遗留下幸福!
亲爱的您,这儿是LearningYard新辅仁。那时小贴士为你增添
乐享聊:Python的程序语言(上)
结语的出访!
Share interests, spread happiness, increase knowledge, and leave beautiful!
Dear you, this is LearningYard Academy.
Today, the editor brings you
Enjoy chatting: Object Oriented Python (I),
welcome your visit!
那时小贴士带着我们一起来介绍呵呵Python的程序语言,Python的程序语言控制技术有:
· 类(Class): 用以叙述具备完全相同的特性和方式的第一类的子集。它表述了该子集中每一第一类所共计的特性和方式。第一类是类的示例。
· 类变量:类变量在整个示例化的第一类中是公用的。类变量表述在类中且在函数体之外。类变量通常不作为示例变量使用。
· 数据成员:类变量或者示例变量, 用于处理类及其示例第一类的相关的数据。
· 方式重写:如果从父类继承的方式不能满足子类的需求,可以对其进行改写,这个过程叫方式的覆盖(override),也称为方式的重写。
· 局部变量:表述在方式中的变量,只作用于当前示例的类。
· 示例变量:在类的声明中,特性是用变量来表示的。这种变量就称为示例变量,是在类声明的内部但是在类的其他成员方式之外声明的。
· 继承:即一个派生类(derived class)继承基类(base class)的字段和方式。继承也允许把一个派生类的第一类作为一个基类第一类对待。例如,有这样一个设计:一个Dog类型的第一类派生自Animal类,这是模拟”是一个(is-a)”关系(例图,Dog是一个Animal)。
· 示例化:创建一个类的示例,类的具体第一类。
· 方式:类中表述的函数。
· 第一类:通过类表述的数据结构示例。第一类包括两个数据成员(类变量和示例变量)和方式。
Today, I will take you to learn about Pythons object-oriented technology. Pythons object-oriented technology includes:
• Class: used to describe the collection of objects with the same properties and methods. It defines the properties and methods common to each object in the collection. An object is an instance of a class.
• Class variable: Class variable is common in the entire instanced object. Class variables are defined in the class and outside the function body. Class variables are not usually used as instance variables.
• Data member: class variable or instance variable, used to process the data related to the class and its instance objects.
• Method rewriting: If the method inherited from the parent class cannot meet the needs of the child class, it can be rewritten. This process is called method override, also called method rewriting.
• Local variable: the variable defined in the method, which only applies to the class of the current instance.
• Instance variable: In the class declaration, attributes are represented by variables. This kind of variable is called instance variable, which is declared inside the class declaration but outside other member methods of the class.
• Inheritance: that is, a derived class inherits the fields and methods of the base class. Inheritance also allows an object of a derived class to be treated as a base class object. For example, there is a design that a Dog type object is derived from the Animal class, which simulates the “is a” relationship (for example, a Dog is an Animal).
• Instantiation: create an instance of a class, a concrete object of the class.
• Method: a function defined in a class.
• Object: an instance of a data structure defined by a class. An object consists of two data members (class variables and instance variables) and methods.
创建类,以下是一个简单的Python类的例子:
Create a class. The following is a simple Python class example:

self代表类的示例,而非类,类的方式与普通的函数只有一个特别的区别——它们必须有一个额外的第一个参数名称, 按照惯例它的名称是 self。
Self represents an instance of a class, not a class. Class methods have only one special difference from ordinary functions – they must have an additional first parameter name, which is conventionally self.

出访特性,您可以使用点号 . 来出访第一类的特性。使用如下类的名称出访类变量:
To access properties, you can use the period To access the properties of the object. Use the following class names to access class variables:

输出结果如下:
The output results are as follows:

Python内置类特性:
__dict__ : 类的特性(包含一个字典,由类的数据特性组成)
__doc__ :类的文档字符串
__name__: 类名
__module__: 类表述所在的模块(类的全名是__main__.className,如果类位于一个导入模块mymod中,那么className.__module__ 等于 mymod)
__bases__ : 类的所有父类构成元素(包含了一个由所有父类组成的元组)
Python built-in class attributes:
__ dict__ : Attribute of the class (including a dictionary, which is composed of the data attribute of the class)
__ doc__ : Class
__ name__: Class name
__ module__: The module where the class is defined (the full name of the class is __main__. className . If the class is located in an import module mymod, the className. __module__ is equal to mymod)
__ bases__ : All parent classes of the class form elements (including a tuple composed of all parent classes)
python第一类销毁(垃圾回收):Python 使用了引用计数这一简单控制技术来跟踪和回收垃圾。在 Python 内部记录着所有使用中的第一类各有多少引用。一个内部跟踪变量,称为一个引用计数器。
当第一类被创建时, 就创建了一个引用计数, 当这个第一类不再需要时, 也就是说, 这个第一类的引用计数变为0 时, 它被垃圾回收。但是回收不是”立即”的, 由解释器在适当的时机,将垃圾第一类占用的内存空间回收。
Python object destruction (garbage collection): Python uses the simple technique of reference counting to track and collect garbage. The number of references of all objects in use is recorded in Python. An internal trace variable, called a reference counter.
When an object is created, a reference count is created. When the object is no longer needed, that is, when the reference count of the object becomes 0, it is garbage collected. However, recycling is not “immediate”. The interpreter will recycle the memory space occupied by garbage objects at an appropriate time.
那时的撷取就到这儿了。
如果您对那时的文章有独特的想法,
欢迎给我们留言,
让我们相约明天,
祝您那时过得开心欢乐!
Thats it for todays sharing.
If you have a unique idea about today’s article,
Welcome to leave us a message,
Let us meet tomorrow,
I wish you a happy day today!
本文由learningyard新辅仁原创,如有侵权,请联系我们。
文字&图片参考:菜鸟教程
翻译:百度翻译
文字&排版|calm
审核|闫庆红