The idea of this thread is to help the beginning Python programmer with hints and helpful code. Please feel free to contribute! If you have any questions start your own thread!
The creators of Python are very active, improving the language all the time. Here is a little of the version history:
Python24 March 2005
Python25 Sept 2006
Python26 Sept 2008
Python27 July 2010 (final version of the Python2 series)
Python32 February 2011
Python33 September 2012
Python34 March 2014
You can download the version you like free from: www.python.org
As of 2014 stick with Python27 or Python34.
Selfextracting MS Installer files have a .msi extension and contain the version number, for instance python-3.4.1.msi.
Python3 is not totally campatible with Python2. A few clumsy things have been removed to modernize the language. One obvious one is the print statement, which is now a print() function and raw_input() has been changed to just input(). The old numeric input() is gone.
You can find an excellent discussion of Python2 to Python3 changes here:
(check appendix A for Py2-to-Py3 differences)
The good news is that Python3 contains a conversion program 2to3.py that will convert your present Python2 code to Python3 code.
Linux users can install Python installers from: http://www.activestate.com/activepython/python3/
For the folks who like to do the unusual, Python is equally at home on the Apple computers. It is my understanding that Linux and Apple OS X have Python already installed. Apple users should check http://undefined.org/python/
I installed my Python on the C: drive, so so version 3.4 I ended up with a C:\Python34 folder after the installation. The first step is to create a subfolder (subdirectory) for all your test programs, like C:\Python34\Atest34.
There is a Python editor included with the Python installation. The program is called IDLE, a small, but capable Integrated Development Environment (IDE), that you can use to write, edit, run and debug your code from. The problem is that it is hidden in subfolders. I found it in
The .py or .pyw extension is used for Python code files. With Windows, all you need to do is to double click on idle.pyw and after a fraction of a second the compiled program appears on your screen.
If your version of IDLE starts up in the Shell Window, the one with the >>> prompts, go to 'Options' on the top line and then click on 'Configure IDLE'. In the configure menu go to the 'General' page and set the 'Open Edit Window' at startup option, then click on 'Apply'.
I think that coding in the interactive shell, also called the command line option, is limited to one liners, simple calculations and calls for help. Anything else is just major confusion, and has turned off a lot of fine folks from using Python! Lamentably, much of the Python docs are littered with command line examples with its many >>> prompts and ... line indent markers. Do not use those >>> prompts and markers in your code editor.
Once you are in the Edit Window with its simple flashing cursor, type in your first Python program (no, the line number is not part of the code).
print( "Hello Monty Python!" )
On the top menu bar click on File and save the short program in the Atest folder as HelloMP1.py now press the F5 key (or click on Run then on Run Module). The Python interactive Shell appears telling what version of Python you are running, and wedged between >>> prompts is Hello Monty Python!
Not much, but it worked, your first Python program. After you admired this for a while, press the Alt and F4 keys at the same time (or File then Close) to leave the Shell and get back to the Editor.
Let's create a second version of the simple program. Replace 'print' with 'str1 =' and add a few more lines ...
str1 = "Hello Monty Python!" # this is a comment # notice you don't have to declare the variable type print( str1 )
If you want to, you can save this under a different filename, then press F5. The result looks the same, but we introduced a string variable and the fact that Python does not require us to declare the type. Oh gee! My C brain is going nuts!
One more change for the fun of it ...
str1 = "Hello Monty Python!" # let's replace the M with Spam str2 = str1.replace('M', 'Spam') # one more Spam for the P str3 = str2.replace('P', 'Spam') # now look at the result print( str1 ) print( str2 ) print( str3 )
Notice, as you type 'str1.replace(' a hint line pops up showing you what can be entered between the function's parentheses, a cool thing. When you are done typing the code, press F5 and enjoy your labor. I leave it to you to dream up better stuff! Also notice, that in all of this the original string str1 has not changed.
Want more? When you are in the IDLE editor simply press the F1 key and a copy of the Python documentation comes up. There you can click on Tutorial and now you have a ton of sample code to play with. Just cut and paste and experiment.
If you are in the Python interactive Shell, the one with the >>> prompt, you can just type help('string') to get a list of string functions and constants. A little cryptic at first, but still useful. In the Shell you can also do calculator stuff and get the result. For instance type 12345679 * 63 then press enter. By the way, you can also get into a somewhat uglier looking Shell when you simply run Python.exe from the Python31 folder.
For convenience sake make a shortcut of idle.pyw and drag it onto your desktop.
Just a note, I said earlier that with Python you don't have to declare the type of a variable. That is not totally true, you have to give Python an idea what it is. By inference Python figures out that if you type z = 77 then z is the reference to an integer object. Conversely z = "Hello" would be a string, z = 7.12 is a floating point number, and z =  is a list (in this case an empty list ready to be populated).
You can find some Python tutorials at:
For GUI programming there are third party modules available:
Tkinter usually comes with the Python installation
wxPython and project Phoenix at http://www.wxpython.org/download.php
PyQT at http://www.riverbankcomputing.com
PySide at http://qt-project.org/wiki/PySide
I recommend PySide.
The Python Image Library (PIL, now pillow) is at:
The PyGame module for game programming is at:
Also look at this site for other Python third party modules:
(mostly binary Windows installers, now wheels)
A detailed and interesting essay about Python's creation and architecture:
Another good introduction into the design philosophy of Python:
Google offers a great Starting Python Class online:
Nice humor ...
A Foolish Consistency is the Hobgoblin of Little Minds ...
for recommended Python code writing style see:
I have started to update some of the posts to reflect changes in Python3. Also changed some of the code to make it work with Python2 and Python3 versions. This is work in progress, tough for my old tired eyes. You will see the somewhat odd print( text ) rather than the recommended print(text), just a visual aid for me that I changed this from Python2. Remember in Python readability rules!
In order to visualize the execution of your Python code line by line use
For those of you who are used to the Microsoft Visual Studio there is a free Python option, check out:
A great website with a lot of hand holding advice.
On my iPad I use an IDE app called "Pythonista" that does a nice job with Python 2.7 (also has PIL, numpy, matplotlib, and a UI-editor). The app costs just a few bucks in the apple app store. See also:
Edited 1 Year Ago by vegaseat: sticky