Learning: Python learning path (6): class and Object
In layman's terms, classes are definitions, and objects are entities.
Simply put, people are classes, and Gao Peng is an object.Attribute
Attributes include instance attributes and class attributes.
Let's take a look at the previous Code:
Class Fruit:
Price = 0
This article mainly introduces the class and object learning tutorials in Python object-oriented programming. object-oriented is the basic feature of Python, the features and usage of classes and objects are the basic skills in Python learning. if you need them, you can refer to everything in
I want to familiarize myself with the third subclass of the compiling class of Python.
As for the class, you may already feel it. Read the following code carefully and see if any problems can be found?Copy codeThe Code is as follows:#! /Usr/bin/env python# Coding: UTF-8
Class
A proper understanding of Python functions can help us to better understand the high-order techniques of Python decorators, anonymous functions (lambda), functional programming, and so on.Functions are an integral part of the programming language, which is commonplace. But a function as the first class object (first-class
Python's object base class __del__ method
This method of Python is a destructor that executes when an instance is destroyed, destroys the memory associated with the instance, methods, attributes, and so on. Also, if the base class specifies a particular property or other method, the subclass also needs to be explici
address of a[0] and the address of a[2] differ by 48 (2 24).
When the a[1] is modified again, the address of a[1] also changes, interestingly, this a[1] address and a[0] address is 24, and the original a[2] Difference 72 (3 24).
Finally, when the address of the number 0 is printed directly, it is found to be exactly the same as the address of the first a[0].
At this point, it is basically possible to say that even the elements in the list are actually references. Modifying the elements in the l
Here we will explain in detail the Descriptor class in Python in the future, including defining the Descriptor and displaying how to call the Descriptor. if you need a friend, refer to the Descriptor as a class to reconcile attribute access. The descriptor class can be used to obtain, set, or delete attribute values. D
Design of the classThe design of the Python oop is discussed here, that is, how to use classes to model useful objects. The commonly used OOP design patterns in Python, such as inheritance, composition, delegation, and factory, will be written. It also introduces some concepts of class design, such as pseudo-private property, multi-inheritance, etc.==============
This article mainly describes the Python meta-class instance resolution, the main task of this article is to give you a thorough understanding of what is a meta-class, the need for friends can refer to the next
Uncle Turtle invented Python and then integrated a bunch of concepts into the language, such as: iterators,
statement actually simply lets A[0] point back to another object. In addition, it is noted that the address of a[0] differs from that of a[2] by 48 (2 24).
When the a[1] is modified again, the address of the a[1] is also changed, interestingly, the address of this a[1] and a[0] differ by 24, and the original A[2 is 72 (3 24).
Finally, when the address of the number 0 is printed directly, the address is found to be exactly the same as the address of the first a[0].
At this point, the basic ca
The examples in this article describe the specialized methods for Python classes. Share to everyone for your reference. The specific analysis is as follows:
Python classes can define specialized methods that are called by Python for you in special cases or when using special syntax, rather than directly in code (as in normal methods).
1. __init__
Similar to cons
The definition format of the class:Class CLASSNAME (parent Class 1, parent Class 2, parent Class 3):__a = 0 # #私有属性, two _ starts, only functions in that class can accessB = 0 # #公共属性def function name (self):Self.__a = ... #访问私有属性名Self. B = ... #访问公共有属性名Ps:1, when defining the function, must have self this parameter, a
Body
The first thing to be explained is that Python classes are divided into classic classes and new classes.The classic class is python2.2, but it's still compatible in 2.7, but the version after 3 only admits the new class.New classes can be used in later versions of python2.2
The difference between a classic class and a new
As an inheritance of the ABC language, the Python programming language helps developers solve some difficult problems. In addition, it is easy to use and greatly improves the development efficiency. We will introduce the usage of the Python Thread class in detail today.
Analysis of basic Python naming conventions
About the class, reader must have had the feeling, look at the following code, please read carefully, and see if you can find something wrong?
Copy Code code as follows:
#!/usr/bin/env python
#coding: Utf-8
Class Person:def __init__ (self, name, Lang, email):Self.name = NameSelf.lang = LangSelf.email = Email
def author (self):Return Self.name
This time for you to bring Python's meta-class how to use, the use of Python meta-class considerations are what, the following is the actual case, take a look.
Today my task is to thoroughly understand what is a meta-class and look together.
To understand the meta-class, le
The examples in this article describe the class methods that are bound and unbound in Python. Share to everyone for your reference, as follows:
Like a function, a class method in Python is also an object. Because methods can be accessed either through an instance or through a clas
# Python class static methods and class method differences# # First Look at the syntax, Python class syntax There are three methods, instance methods, static methods, class methods.This article is written by Huanggo
__str__ and __repr__If you want to turn an instance of a class into str, you need to implement a special method __str__ ():class Person (object): __init__(self, Name, gender): self.name = name Self.gender = Gender def __str__(self): return ' (Person:%s,%s) '% (Self.name, self.gender) Now try print on the interactive command line:>>> p = person (' Bob ', ' Male ') >>> print P (pe
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.