lec_2.txt - Compound data types: strings, lists, tuples So far we have mainly dealt with primitive data type values (and a little bit about strings). That is, we have seen four types: int, float, bool, and string. Strings are compound data whereas the other three are atomic. That is, a string is made up of smaller pieces, characters. Our main focus so far has been learning the basic language constructs such as operators, conditionals, loops, functions, input, etc. using simple data types. We are now ready to learn more complex data, i.e., compound data. The ones we will learn include strings (in more detail), lists, and tuples. To write realistic programs, we will need to know these compound data types as well. Let's do it. - Strings . see strings.py - Lists . see lists.py - Tuples and Dictionaries . These are also compound data types and we will study them, but let us study modules first before we continue with them. - Modules . see modules.py . see seqtools.py . see init.py - Tuples . see tuples.py - Dictionaries . see dictionaries.py - We have now seen enough basic data sturctures that you will need in Python to write some interesting programs. We will now study how to deal with data in a file. - Files . see files.py - Exception handling . see exceptions.py - Classes and objects . see objects.txt . see points.py - Array . The array module defines a new object type, array, that works almost exactly like other sequence types, except that its contents are constrained to a single type. That is, only one type of elements can be included in an array. The type of of an array is determined at the time of creation. . This module is used to create large lists in a storage-efficient manner. The resulting arrays are not suitable for serious numeric work due to its inefficient implementation. To create storage- and calculation-efficient arrays, I suggest you use NumPy arrays instead, which I will present next. . Another key difference: the Standard Python class array is only for one-dimensional arrays, whereas the multidimensional array class called 'ndarray' in NumPy is obviously multidimensional. - Python, NumPy, and SciPy: Why All These? The Python language provides an array package, but it supports only one-dimensional arrays. This package is also rather inefficient for numeric computation. NumPy provides among other things an n-dimensional array package that is convenient and fast. It basically depends on an efficient implementation done in another language that is being used by Python. If we were to classify programming languages into 'fast' ones and 'slow' ones, Python would be considered as one of the 'slow' ones. When you deal with computations that require speed in Python, Python relies on the help of other 'fast' languages such as C, C++, Fortran. NumPy is one such example. Later, you will see SciPy which is open-source software for mathematics, science, and engineering. SciPy is built using a library which relies on NumPy arrays and provides many user-friendly and efficient numerical routines such as numerical integration and optimization. - NumPy Document: Guide to Numpy, Travis E. Oliphant . A piece of warning first: page 38 No. 4 Default data type in NumPy states: The default data-type in NumPy is float unlike in Numeric (and numpy.oldnumeric) where it was int. There are several functions affected by this so that if your code was relying on the default data-type, then it must be changed explicitly by adding dtype = int. . see arrays.py for an introduction to NumPy arrays. - SciPy . See the section "Python, NumPy, and SciPy" above to see what it is. . I will not cover it in this tutorial. Instead I will refer you to an online tutorial on SciPy: http://www.scipy.org/SciPy_Tutorial . As a preparation for the upcoming workshop, I believe the material on NumPy would be sufficient. - This is the end of my short tutorial on Python that would be needed for the workshop. Have fun at the workshop !