An Introduction to Python


Programs are simply sequences of instructions to the computer that are written in a computer language.  The computer language you decide to learn (python in this case) is used to combine specific words into a set of instructions that can be a single line or many many lines.  You will have to be very exact with the syntax.  Luckily editors help us create code in the correct syntax needed.

Python Versions

There are two version of python for you to learn with. A version that is 2.7.x and 3.3.x. I will mostly be using Python 3 version and will use version 2 only if a package I wish to use isn't supported by Python 3.  For the most part, the way in which I will be using python there will not be a significant difference.

Python 3 is a newer version but Python 2 is still widely used and they are both still being updated.  There are a few differences in the way some functions work and with the division of integers for example.

for example

Python 2 code

print 'The energy is',E

and Python 3 code

print ('The energy is',E)

Each of the above examples does the same thing but notice how Python 3 requires the ( ) around what is to be printed. Small differences like this will result between the two versions but which ever version you decide to use will be sufficient to learn the language.

Installing Python
You can install a working copy of python from here Make sure you choose the correct version for your operating system. You can also download packages such as winpython and enthought that will have added libraries for python.

Environment Variables
You will have to make sure to set up python in your PATH. You can do this by using your windows search and typing in "view advanced system properties". At the bottom of the dialog box will be a button "Environment Variables...". You will need to find the system variable named PATH and edit it. At the end you will need to place a semicolon ; and then the path to the directory that you installed python to. This allows you to run python from the command line by simply typing python.

Idle is an interactive shell for you to play with your code. You can use this to get instant results or test small amounts of lines code. I would not recommend creating your entire program this way but it can be very helpful in certain situations.
Editing Python Files
Getting Help
Python Reserved Words
Naming Conventions

Check Install

For starters, lets check if we have python installed correctly.

You can open up a terminal instance on your computer. For windows can be done by typing "cmd" in the start search. Once you have terminal open you can type "python --version" without the quotes to check that you have python installed and its current version that you will be using by default.

You can also type python by itself to enter python's interpretive mode. This simply means you can already start writing a few lines of code and get the results immediately. For example you can type the code

print "Hello World"

Now that is your first line of code in python! Congratulations!!

To create a program that is a bit more complex than the one we just created, we are going to use either eclipse or Aptana to create our code. You can use any other program you wish to create, debug, and manage your code. Before we get started lets take care of one more thing. Lets review some terminology so that we are all on the same page. Quickly check out the terms below and then move with creating your first program.

Tab Content.
Tab Content.
Tab Content.
Tab Content.
Tab Content.
Tab Content.

Leave a Reply

Your email address will not be published. Required fields are marked *