Cute python: Get version 2.0

Source: Internet
Author: User
Tags versions in python

Python programmers have recently acquired a new tool with the release of version 2.0. Python 2.0 was built on the strengths of previous versions of Python, adding a lot of new conveniences and capabilities. This article provides the author's impressions of the latest version of Python and some tips on how to use it effectively.

Python 2.0, released in October 2000, introduces many new language features and includes new standard modules. One of the virtues of van Rossum-probably the title of "lifelong charity ruler (BDFL)" For him in the Python community-is his conservatism in Python changes. He argues that the fewer changes between versions of Python are, the better, and that the changes will be considered and discussed several months or even years in advance. This facilitates python's forward and backward compatibility, as well as the consistency of running Python programs on various platforms and versions. It is said that Python 2.0 has a very big jump in the language definition of Python 1.5x. Fortunately, Python 2.0 still maintains good backwards compatibility, and changes are often quite "Python" in features.

In addition, it is worth noting that the short-lived Python 1.6 was released in September 2000. The release is a bit odd-it exists from the contractual responsibilities of the Python core development team, which found a new organizational home during the same period of 1.6/2.0 development. Most of Python 1.6 is similar to Python 2.0, but if you want to install a new version, it's best to install Python Python 2.0.

For a detailed summary of the changes, please review the resources carefully. This article contains my personal assessment of the most important and interesting content, and some of the changes you are interested in may not be covered here.

List connotation and zip ()

For me, the most exciting new feature of Python 2.0 is adding a list of connotations. (Any curious reader with a mathematical background will notice that this ability is sometimes referred to as "ZF connotation" in other functional languages and is named according to the axiom of content in Zermelo-frankel set theory.) )

Most readers will notice a strange wording in the previous paragraph: "Other functional languages." "As a python programmer, you've been programming with a (mixed) function language since Python 1.0. Of course, if you are not accustomed to using the built-in function lambda (), map (), reduce (), and filter (), you have not yet used these function attributes. But even if you've used these, Python always makes it easy to avoid thinking about function paradigms.

In any case, the list connotation is a way to perform the operations performed by many Python built-in functions, but is more closely used and easier to read and understand. Let's start with an example of the meaning of a simple list in use:

List Connotation sample

>>> xs = (1,2,3,4,5)
>>> ys = (9,8,7,6,5)
>>> bigmuls = [(x,y)

     for
     x

     in
     xs

     for
     y

     in
     ys

     if
     x*y > 25]
>>>

     print
     bigmuls
[(3,9), (4,9), (4,8), (4,7), (5,9), (5,8), (5,7), (5,6)]

In this example, we create a list of tuples in which each tuple element is extracted from another list, and each list element satisfies some attributes. If you do not use the IF clause, we can only create an arrangement (usually useful in themselves), and if we use the IF clause, we can create a filter () type that is truncated to the list. Incidentally, multiple if clauses are allowed in a list connotation.

Fundamentally, there is nothing new in the ability to list content; in Python 1.5x, of course, the same effect can be achieved, but not so clear. For example, some of the more verbose (and therefore less clear) techniques below can do the same thing:

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.