Chapter 3. Managing Data Types


Python has about two dozen data types built in to the interpreter. The three data types that you will need to understand the best and use the most to manage data are the list, tuple, and dictionary.

A list in Python is simply an ordered collection of objects. The objects can be named any legal Python name and the list can grow dynamically to support the addition of new objects. The objects in a list can be of different types and Python will keep track of the data type of objects in the background. Lists in Python are ordered sequence types. Elements of a list are accessible using a zero-based non-negative integer index.

A tuple in one sense is just a read-only version of a list. It is also an ordered sequence of objects. However, a tuple is immutable, meaning that items cannot be added to or removed from it.

A dictionary is an unordered collection of object pairs. The pair consists of a key object and a value object. The key object is used to look up the value of the value object. A dictionary acts similar to a hash table in that the key is used to access the value objects within. There is no order to a dictionary; therefore, items cannot be accessed by any indexing method.

This chapter discusses phrases that allow you to manage data using the list, tuple, and dictionary data types.



Python Phrasebook(c) Essential Code and Commands
Python Phrasebook
ISBN: 0672329107
EAN: 2147483647
Year: N/A
Pages: 138
Authors: Brad Dayley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net