Python2.4 new features early adopters

xiaoxiao2021-03-06  79

The Alpha 2 of Python 2.4 has already been released on August 5th, and it is a little time to see today. After you have made it, share it with you.

First, I can't pay attention to it, 2.4 is built into the language in the language, before being placed in the standard library. The current use is also very flexible:

(Part of the example in the text is taken from the Python.org website)

>>> a = set ('Abracadabra') # Generate a set by a string

>>> 'Z' In a # Quick detection members exist

False

>>> A

Set (['a', 'r', 'b', 'c', 'd'])

>>> '' .join (a) # Transform the elements in the set back to the string

'arbcd'

>>> b = set ('alacazam') # another set

>>> a - b # gets a set of elements belonging to A rather than B

Set (['R', 'D', 'B'])

>>> a | b # a and b

Set (['A', 'C', 'R', 'D', 'B', 'M,' Z ',' L '])

>>> A & B # a and b

set (['a', 'c'])

>>> a ^ b # belongs to a or b but does not belong to elements they intend

Set (['R', 'D', 'B', 'M', 'Z', 'L'])

>>> a.add ('z')

>>> a.Update ('wxy')

>>> A

Set (['a', 'c', 'b', 'd', 'r', 'w', 'y', 'x', 'Z'])

>>> A.Remove ('x') # Delete a set of elements

>>> A

Set (['a', 'c', 'b', 'd', 'r', 'w', 'y', 'Z'])

Other features are trying.

转载请注明原文地址:https://www.9cbs.com/read-121521.html

New Post(0)