Python LearningOn this page ... (hide)
1.? Basic Installation
2.? Python documentation
2.1. Recommended Resources Site
2.2? Other references
2.3? code example
3.? Common tools
3.1? Python IDE
3.2? Built-in class library use reference
3.3? Common Third
1), Python in the definition of the class in the py2-3 version of the use of the new class and the classic class two cases, in the definition of the new class and the classic class is the most important difference is when the
first, the new old class of Python object-oriented 1) New Class (recommended): When defining a class, the class is followed by the base class (object) in parentheses. In python3.x, if the parent
):Self.name = Namedef hi (self):Print Self.nameif __name__ = = ' __main__ ':foo01 = Foo (' Letian ')Foo01.hi ()Print type (Foo)Print type (FOO01)Print ID (foo01)Print ID (Foo)The result of the operation is:Letian4012470431323448[code]As you can see, the type of Foo is Classobj (class object, the class defined in Python is also an object), and the type of FOO01 is
The examples in this article describe the proprietary methods of the Python class. Share to everyone for your reference. The specific analysis is as follows:
A Python class can define a private method that is invoked by Python for you in special cases or when special syntax
Python is an object-oriented language, and as an object-oriented feature-class is also available. It is worth noting that everything in Python is object, not like in C # for performance reasons, int is also an object in Python. (int is struct in C #)How to define a class:1
Notes for using class variables and member variables in python: python Variables
Preface
Recently I was writing a project in python and found a disgusting bug, that is, the data between two instances generated by the same class could affect each other, which made me very puz
There are 4 ways to do this in Python:1) The global method in the module, which does not belong to any class, is called by the "module name. Method Name" form.2) The instance method defined in the class, also becomes the binding method (Bound methods), the first parameter of this method (usually writing self, similar to Java and C + +), must be called the method'
Objective
Students who have used python to write object-oriented code may be familiar with __init__ methods that ,__init__ run immediately when an object in a class is created. This method can be used to do some of the initialization you want for your object.
Note: This name starts and ends with a double underline.
Parent Class A
Summary: python implements the difference between the two methods called by the parent class, and python implements the two methods.
There are two methods in python that can call the method of the parent class:
super(Child, self).method(args)
Parent.method(self, args)
I repo
In python, subclass inherits the _ init _ Method Instance of the parent class, and python _ init _
Preface
If you have written object-oriented code using Python __init__ The method is very familiar.,__init__Method runs immediately when an object of the class is created. This
The concept of classes in Python programming can be compared to the description of a certain type set. For example, "human" can be considered as a class, then we use the human class to define every specific person-you, me, and others as their objects. The class also has attributes and functions. attributes are some cha
dog class.
C + + class definition
Defining a class is essentially a blueprint for defining a data type. This does not actually define any data, but it defines what the name of the class means, that is, it defines what the object of the class includes and what operations c
Http://www.jb51.net/article/49402.htmNote: The Python2.7 is used.First, the example methodAn instance method is a method that an instance of a class can use. As follows: Copy the Code code as follows:class Foo:def __init__ (self, name):self.name = namedef hi (self):Print Self.nameif __name__ = = ' __main__ ':foo01 = Foo (' Letian ')Foo01.hi ()Print type (Foo)Print type (FOO01)Print ID (foo01)Print ID (Foo)The result of the operation is: Copy the Code
New and Legacy classes The new Python class is introduced in version 2.2, and we can call the previous Class A classic or old class. Why introduce the new style class in 2.2? The official explanation is: In order to unify classes (class
The new Python class is introduced in version 2.2, and we can call the previous Class A classic or a legacy class.
Why introduce the new style class in 2.2? The official explanation is:
In order to unify classes (class) and types
.
When a reference is passed to a function, the function automatically copies a reference, and the reference in the function does not have a semi-gross relationship with the outside reference. So the first example is that the function refers to an immutable object number, and when the function returns, the outside reference does not feel half-hairy. And the second example is different, The reference in the function refers to the Mutable object list, which points to the memory address of the
: Universal code, a standard encoding, Python2 the encoding that is used by default. At least 16 bits are required to store. Other encodings are optimized for this encoding, such as UTF-8,GBK.UTF-8: Compression and refinement of Unicode (numbers, letters and ASCII codes using 8-bit encoding to store), Python3 default encoding used, European characters: 2 bytes, 16-bit storage; Chinese characters: 3 bytes, 24 bit storage Summary: Python3 default encoding is UTF-8, encoding conversion principle:
is used, Python searches from left to right, that is, when the method is not found in the subclass, the parent class is searched from left to right to include the method
#另一个类, the preparation of multiple inheritance before class speaker (): topic = ' name = ' def __init__ (self,n,t): self.name = n Self.topic = T def speak (self): print ("I a
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.