Python Learning _10__python2 to Python3

Source: Internet
Author: User

Similarly, as a dynamic language, Python has a lot of similarities with Ruby, and it is recommended to refer to the object of learning Python in Ruby meta-programming. However, Python is not a purely object-oriented design, so many of Ruby's flexible techniques may not work in Python, but this does not affect the book's reference to Python-oriented learning.

Starting with classes and instances, talking about Python2 to Python3

Classes and instances are object-oriented, class is the definition of an object, such as human definition of people should have the basic properties and methods, and instances are real objects, instances of the specific information stored in the object, such as Xiao Ming is an example of human beings, Xiao Ming's height and weight information constitute the specific information of xiaoming this object. However, the class province is also an object, the new class is all inherited from a parent class, object is the ancestor of all classes, is the ancestor class of the most top building, the object is also a class of objects, Python, the class of object is no longer called class, but the type, Any class defined with the Class keyword is an instance of type.

Classes can be created by using the Class keyword:

Class Mynewobjecttype (Bases):
? ? ' Define Mynewobjecttype class '
? ? Class_suite

In Python2, this is actually a mess, the classic class: There is no class inherited from other classes, there is no __class__ property, through the type () method, you can see that the type of the classic class is: <type ' classobj ' >; and the new class, That is, by inheriting classes from other classes, the type is that Type,python has tried to unify type and class, but obviously in python2, these concepts can still be confusing to some people:

Class CLS1:
? ? Pass
Print type (CLS1)
Class Cls2 (object):
? ? Pass
Print type (CLS2)
Print cls2.__class__

The result of the above code is:

<type ' Classobj ' >
<type ' type ' >
<type ' type ' >

If you're addicted to pure object-oriented syntax like Ruby, Python2 may be overwhelming, and these legacy issues are resolved in Python3 to make their support for object-oriented more excellent.

in view of the above reasons, in the Python object-oriented learning, all use Python3, python3 because a lot of python2 incompatibility is questioned, but at least in the right direction, if not change some of the problems left in Python2, When the Python library more and more, it is difficult to avoid more problems, Python3 upgrade at the same time will also say some python2 in the inferior library to do a phase out, the quality of the library will certainly be in the community to get priority to transplant, from the language itself, this is not a good thing, Can let Python3 get rid of a lot of historical baggage, and have more excellent grammar, also let me have better expectations. From Python2 to Python3 is an important decision, he may have lost a lot of python, and may even let python out of the stage, but I still optimistic about it, compared to Java on the expansion pack of indifference, Python3 's self-denial reform has set a new stage for Python.

New features in Python3

http://my.oschina.net/lenglingx/blog/205626

Some of the common features mentioned above are

Python Learning _10__python2 to Python3

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.