12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Other Core TypesBeyond the core types we’ve seen so far, there are others that may or may not qualifyfor membership, depending on how broad the category is defined to be. Sets, forexample, are a recent addition to the language. Sets are containers of other objectscreated by calling the built-in set function, and they support the usual mathematicalset operations:>>> X = set('spam')>>> Y = set(['h', 'a', 'm']) # Make 2 sets out of sequences>>> X, Y(set(['a', 'p', 's', 'm']), set(['a', 'h', 'm']))>>> X & Y # Intersectionset(['a', 'm'])>>> X | Y # Unionset(['a', 'p', 's', 'h', 'm'])>>> X – Y # Differenceset(['p', 's'])In addition, <strong>Python</strong> recently added decimal numbers (fixed-precision floating-pointnumbers) and Booleans (with predefined True and False objects that are essentiallyjust the integers 1 and 0 with custom display logic), and it has long supported a specialplaceholder object called None:>>> import decimal # Decimals>>> d = decimal.Decimal('3.141')>>> d + 1Decimal("4.141")>>> 1 > 2, 1 < 2 # Booleans(False, True)>>> bool('spam')True>>> X = None # None placeholder>>> print XNone>>> L = [None] * 100 # Initialize a list of 100 Nones>>> L[None, None, None, None, None, None, None, None, None, None, None, None, None,...a list of 100 Nones...]>>> type(L) # Types>>> type(type(L)) # Even types are objectsOther Core Types | 87

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!