Py-Tut-001

__**Back to Learning Python**__

Excited?! Good! You Should Be!! :)
Here we will cover a few points
 * 1) Comments
 * 2) The "print" Function aka Our First Program
 * 3) How to run our program within TextWrangler
 * 4) Assignment 1

Remember, we are using TextWrangler as our editor so start it up now if you have not already done so.

1. Comments
Comments in a program are one of the most important features of any programming language. If you are reading this tutorial as a student in my class, you should know that for your assignments I value proper documentation more highly than a working program.

To add a comment to a line, make sure the first character is the hash symbol "#".

For example,

code format="python" code
 * 1) This line is a comment :)

2. The "print" Function aka Our First Program
A very important detail of Python is that all code must be indented together. There are no braces or other begin/end delimiters to separate blocks of continuous coding. Indentation is used to block code together. This means you indent the same amount for each line of code that belongs together. We will cover this in more detail later.

To print information to the screen,

code format="python" print "And Now for Something Completely Different" code

3. How To Run Our Program in TextWrangler
Within TextWrangler, type the command from Step 2 above and save the file onto your computer. Make sure you save it with a ".py" extension. Once saved, TextWrangler will now know your file is a Python program and will use syntax colouring. To run the program, click the TextWrangler top menu of "#!" and select "Run in Terminal"

You should see an output similar to the following:



There is a lot of gobbledegook garbage at the beginning having to do with system stuff. Ignore that. The important part is that you should see the line "And Now for Something Completely Different". This is the output of your program. Congratulations! On your Mac you can close the terminal with Command-Q.

Make sure you are comfortable with these steps. Now that you are up and running, tutorials that follow will focus more on Python and less on the environment.

Assignment 1
Write a program that prints your name. Save it as "Py-tut-001.py"

__**Back to Learning Python**__