Python Study Group

Indentation Sensitive

One thing that sets Python apart from other languages is that it is indentation sensitive! You might see this refered to as whitespace sensitive, also.

Take, for instance, an "if" statement:

 >>> if 3 > 4 :
 ...     print "Greater than"
 ... else :
 ... print "Less than"
   File "<stdin>", line 4
     print "Less than"
 IndentationError: expected an indented block

Indenting the fourth line produces the desired result.

 >>> if 3 > 4 :
 ...     print "Greater than"
 ... else :
 ...     print "Less than"

 Less than

So, the indentation, or whitespace, is not merely for looks, but a part of the language and has meaning.

Hello Python

 def hello_world():
     print 'Hello World!'


Standard input and output

To have Python standard input output we need to use the print and raw_input(), print will become a function on Python 3000 but so far it's still a command. Here is the code sample:

''' - Ask your name and replies with your name '''

print 'Please enter your name.'
name = raw_input()
print 'How are you, ' + name + '?' 

Or, alternatively, we can pass the prompt to raw_input() directly:

name = raw_input('Please enter your name: ')
print 'How are you, ' + name + '?' 

We run the program and we can get the following:

 $ python
Please enter your name
How are you Dann? 


Python Lectures Recordings

A lecture by Dr. Sergio Rey of San Diego St. University on Python Data Sturctures, including strings, lists, tuples, dictionaries and sets.


So, in order to work together, it seems we'll need a text to work from, but which book to use? The current books that have been recommended or mentioned are:

  • Python Programming
    • Also links to several other online books and resources, available in a printable format. Likely to be the text used.
  • Byte of Python
    • Seems like a nice book, too. From the site:
      This book serves as a guide or tutorial to the Python programming language. It is mainly targeted at newbies (those who are new to computers). It is also useful for experienced programmers who are new to Python. Might be more complete than Python Programming
  • Dive into Python
    • A book published by Apress, available in several formats for download, but written with experienced programmers in mind.
  • Thinking in Python
    • An advanced text to use after learning the basics, listed as a 0.1 version, and this book recommends Byte of Python as an intro text. Looks like it could be out of date, though.

We're leaning towards Python Programming, so that will likely be the text to use, starting with the Interactive shell.

Python Tutor Mailing List

Visit Python Tutor Mailing List to sign up for questions and answers. You can choose the daily digest or receive them as they come, and of course the list runs on mailman, a Python-based mailing list.

Python Code Examples

Python Forum

Get feedback and ongoing discussion at the TLLTS Forum. Other Python forums include Python Forum