Python 2/3 Version differances

A place where you can post Python-related tutorials you made yourself, or links to tutorials made by others.

Python 2/3 Version differances

Postby Yoriz » Fri Feb 22, 2013 2:35 pm

Note This post was written by metulburr

Currently the most widely used version are Python2.x and Python3.x. The difference within each version is almost pointless to mention. You will either have some form of 2.x or some form of 3.x. You can have both 2.x and 3.x installed on the same system and run each separately.

Normally when you think of versions, you expect the latest to be the best, right? If you are looking for 3rd party modules to use with your python scripts, then python2.x currently has the lead, because not everything has been ported to python3.x yet. If your installing a module for python and your using 3.x, read up on the documentation for that module to check if it is 3.x comparable.

If your using Python3.x, you will surely come across code online more often written in Python2.x. For beginners, the problem lies in different modules renamed, placed elsewhere, etc. that will confuse the hell out of you. If you attempt to run example code and find you have an import error while running Python3.x, the problem is more often a conflict of version. This Porting Guide will allow you to easily find the problem and correct it with the proper Python3.x module.

How to check your version?

If you don't know what version you are using, there are a few methods to use to find out. One way is in the python interpreter itself.
Code: Select all
>>> import sys
>>> sys.version
'3.2.3 (default, Oct 19 2012, 20:10:41) \n[GCC 4.6.3]'


In a terminal or DOS prompt, running python with the argument -V, will give you the version.
Code: Select all
metulburr@ubuntu:~$ python -V
Python 2.7.3
metulburr@ubuntu:~$ python3 -V
Python 3.2.3
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1009
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest