Introduction
Python is an interpreted dynamically typed Language. Python uses indentation to create readable, even beautiful, code. Python comes with so many libraries that you can handle many jobs with no further libraries. Python fits in your head and tries not to surprise you, which means you can write useful code almost immediately.
Python was created in 1990 by Guido van Rossum. While the snake is used as totem for the language and community, the name actually derives from Monty Python and references to Monty Python skits are common in code examples and library names. There are several other popular implementations of Python, including PyPy (JIT compiler), Jython (JVM integration) and IronPython (.NET CLR integration).
Python 2.x vs. Python 3.x
Python comes in two basic flavors these days – Python 2.x (currently 2.7) and Python 3.x (currently 3.3). This is an important difference – some code written for one won't run on the other. However, most code is interchangeable. Here are some of the key differences:
Python 2.x | Python 3.x |
---|---|
print “hello” (print is a keyword) | print(“hello”) (print is a function) |
except Exception, e: # OR except Exception as e |
except Exception as e: # ONLY |
Naming of Libraries and APIs are frequently inconsistent with PEP 8 | Improved (but still imperfect) consistency with PEP 8 guidelines |
Strings and unicode | Strings are all unicode and bytes type is for unencoded 8 bit values |
There is a utility called 2to3.py that you can use to convert Python 2.x code to 3.x, while the '-3' command line switch in 2.x enables additional deprecation warnings for cases the automated converter cannot handle. Third party tools like python-modernize and the 'six' support package make it easy to target the large common subset of the two variants for libraries and applications which support both 2.x and 3.x.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}