Python Variables and Data Structures


Python has four variable types: scalars, lists, tuples, and dictionaries.

  • Scalar variables are those that hold a single value, much the same as in Perl. Although unlike Perl, numeric and string types are segregated and no extra symbols are prefixed to variables in Python. Examples of numeric and string scalar variable assignments are

    x = 5 pi = 3.14159 animal = "dog" 

  • Lists are numerically indexed lists of objects. They can be made up of any combination of things you choose, such as scalar data, dictionaries, tuples, and even other lists. An example of a list assignment is

    months = ["January", "February", "March", "April", "May", "June",  "July", "August", "September", "October", "November", "December"] 

  • Tuples are almost identical to lists, except they are immutable. That means unlike a list, which you can change and modify any way you like, you cannot change a tuple.

  • Dictionaries are associatively indexed arrays comparable to Perl's hashes. They are a collection of objects or values arranged in key/value pairs. An example of a dictionary assignment is

    birthdays = {"mom" : "SEP 06", "jean" : "JUN 01", "marc" : "JUN 16"} 



SUSE Linux 10 Unleashed
SUSE Linux 10.0 Unleashed
ISBN: 0672327260
EAN: 2147483647
Year: 2003
Pages: 332

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