Python programming language
Python is an
interpreted programming language created by
Guido van Rossum in
1990. Python is fully
dynamically typed and uses
automatic memory management; it is thus similar to
Perl,
Ruby,
Scheme,
Smalltalk, and
Tcl. Python is developed as an
open source project, managed by the non-profit
Python Software Foundation, and is available for free from
the project website. Python 2.4.3 was released on
March 29,
2006.
Python is notable amongst current popular
high-level languages for having a
philosophy that emphasizes the importance of the programmer over the importance of the computer (so that, for example, code is slower but easier to understand) and for rejecting more arcane language features. Python is often characterised as minimalistic, though this only applies to the core language's syntax and semantics; the
standard libraries provide the language with a large number of
additional libraries and extensions.
The
de facto standard for the language is the CPython implementation, although there are
other implementations available. Miscellaneous parts of the language have formal specifications and standards, but not the language as a whole.
Python 1
Python was created in the early
1990s by Guido van Rossum at
CWI in the
Netherlands as a successor of the
ABC programming language. van Rossum is Python's principal author, and his continuing central role in deciding the direction of Python is jokingly acknowledged by referring to him as its
Benevolent Dictator for Life (BDFL).
The last version released from CWI was Python 1.2. In 1995, van Rossum continued his work on Python at the
Corporation for National Research Initiatives (CNRI) in
Reston, Virginia where he released several versions of the software. Python 1.6 was the last of the versions released by CNRI.
Following the release of Python 1.6, and after van Rossum left CNRI to work with commercial software developers, it became clear that the ability to use Python with software available under the GPL was very desirable. CNRI and the
Free Software Foundation (FSF) interacted to develop enabling wording changes to the Python's
free software license that would make it GPL-compatible. That year, van Rossum was awarded the
FSF Award for the Advancement of Free Software.
Python 1.6.1 is essentially the same as Python 1.6, with a few minor bug fixes, and with the new GPL-compatible license.
Python 2
In 2000, the Python core development team moved to
BeOpen.com to form the BeOpen
PythonLabs team. Python 2.0 was the first and only release from BeOpen.com. After Python 2.0 was released by BeOpen.com, Guido van Rossum and the other PythonLabs developers joined
Digital Creations.
Python 2.1 was a derivative work of Python 1.6.1, as well as of Python 2.0. Its license was renamed
Python Software Foundation License. All intellectual property added, from the time of Python 2.1's alpha release on, is owned by the Python Software Foundation (PSF), a non-profit organization modeled after the
Apache Software Foundation.
Python developers have an ongoing discussion of a future version called
Python 3.0 (the project is called "Python 3000" or "Py3K") that will break backwards compatibility with the 2.x series in order to repair perceived flaws in the language. The guiding principle is to "reduce feature duplication by removing old ways of doing things". There is no definite schedule for Python 3.0, but a PEP (Python Enhancement Proposal) that details planned changes exists. [
1]
Planned changes include:
* move
map,
filter and
reduce out of the built-in
namespace (the rationale being that
map and
filter are expressed more clearly as
list comprehensions, and
reduce more clearly as an accumulation loop)
* add support for optional type declarations
* unify the
str/
unicode types, and introduce a separate mutable
bytes type
* convert built-ins to returning iterators (instead of lists), where appropriate
* remove backwards-compatibility features like classic classes, classic division, string exceptions, implicit relative imports
The Python programming language is actively used in industry and academia for a wide variety of purposes. Some of the largest projects that utilise Python are the
Zope application server and the
Mnet and
BitTorrent file sharing systems. It is also extensively used by
Google. [
2]
Python was designed to be a highly readable language. It aims toward an uncluttered visual layout, uses English keywords frequently where other languages use punctuation, and has notably fewer syntactic constructions than many structured languages such as C, Perl, or Pascal.
Indentation
Python uses indentation, rather than
curly braces, to delimit
blocks. An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.
Control structures and statements
Python's statements include:
*
if statement, for conditionally executing blocks of code, along with
else and
elif (a contraction of else-if).
*The
while statement runs a block of code until a condition is
False.
*
for loops iterate over an iterable, capturing each element to a local variable for use by the attached block.
*
class statements execute a block of code and attach its local namespace to a
class, for use in
object oriented programming.
*
def defines a
function.
Each statement has its own semantics: for example, the
def statement does not execute its block immediately, unlike most other statements.
Standard Python does not support
continuations, and according to Guido van Rossum,
never will. However, better support for
coroutine-like functionality is planned, by extending Python's generators [
3].
Type system
Python espouses
duck typing, also known as
latent typing. Type constraints are not checked at
compile time; rather, operations on an object may fail, signifying that the given object is not of a suitable type. Despite not enforcing
static typing, Python is
strongly typed, forbidding operations which make little sense (for example, adding a number to a string).
Fundamental datatypes
Python includes a number of different
datatypes. Amongst the most used are:
*
int — an
integer*
list — a
mutable sequence.
*
tuple — an
immutable sequence.
*
str — an
immutable sequence of
characters.
*
dict — a
dictionary.
*
set — an approximation of a
mathematical set (an unordered collection, where each element can only appear once).
This list is not exhaustive; there are many other types provided by Python - these are merely some of the most commonly used.
The standard Python interpreter also supports an
interactive mode in which it acts as a kind of
shell: expressions can be entered one at a time, and the result of their evaluation is seen immediately. This is a boon for those learning the language and experienced developers alike: snippets of code can be tested in interactive mode before integrating them into a proper program. As well, the Python shell is often used to interactively perform system tasks, such as modifying files.
The mainstream Python implementation, also known as
CPython, is written in
C, and is distributed with a large standard library written in a mixture of C and Python. CPython ships for a large number of supported platforms (see below) and can be ported to other platforms, most readily to
POSIX (Unix-like) systems.
There are two other major implementations,
Jython for the
Java environment, and
IronPython for the
.NET and
Mono environment.
PyPy is an experimental
self-hosting implementation of Python, in Python, that can output a variety of types of
bytecode and
object code.
CPython supported platforms
The most popular (and therefore best maintained) platforms Python runs on are
Linux,
BSD,
Mac OS X,
Solaris, and
Microsoft Windows.
Python was originally developed as a
scripting language for the
Amoeba operating system capable of making
system calls; however, that version is no longer maintained.
Many third-party libraries for Python (and even some first-party ones) are only available on Windows, Linux, BSD, and Mac OS X.
 |
Python comes with "batteries included" |
Python has a large
standard library, which makes it well suited to many tasks. This comes from a so-called "batteries included" philosophy for Python modules.The modules of the standard library can be augmented with custom modules written in either C or Python. The standard library is particularly well tailored to writing Internet-facing applications, with a large number of standard formats and protocols (such as
MIME and
HTTP) supported. Modules for creating
graphical user interfaces, connecting to
relational databases, arithmetic with
arbitrarily precise decimals, and manipulating
regular expressions are also included. Python also includes a
unit testing framework for creating exhaustive test suites.
The standard library is one of Python's greatest strengths. The bulk of it is cross-platform compatible, meaning that many Python programs can often run on Unix, Windows, Macintosh, and other platforms without change.
It is currently being debated whether or not third-party but open source Python modules such as
Twisted,
NumPy, or
wxPython should be included in the standard library, in accordance with the batteries included philosophy.
Multiple paradigms
Python is a
multi-paradigm language. This means that, rather than forcing programmers to adopt a particular style of programming, it permits several styles:
Object orientation,
structured programming,
functional programming, and
aspect-oriented programming are all supported. Many other paradigms are supported using extensions, such as
pyDBC and
Contracts for Python which allow
Design by Contract. Python is
dynamically type-checked and uses
garbage collection for
memory management. An important feature of Python is dynamic
name resolution, which binds method and variable names during program execution.
Another target of the language's design is ease of extensibility. New built-in modules are easily written in
C or
C++. Python can also be used as an extension language for existing modules and applications that need a programmable interface.
Though the design of Python is somewhat hostile to
functional programming (no
tail-call elimination or good support for anonymous closures) and the
Lisp tradition, there are significant parallels between the philosophy of Python and that of minimalist Lisp-family languages such as
Scheme. Many past Lisp programmers have found Python appealing for this reason.
Minimalism
While offering choice in coding methodology, Python's designers reject exuberant syntax, such as in Perl, in favor of a sparser, less cluttered one. As with Perl, Python's developers expressly
promote a particular "culture" or ideology based on what they want the language to be, favoring language forms they see as "beautiful", "explicit" and "simple". As
Alex Martelli put it in his
Python Cookbook (2nd ed., p.230): "To describe something as clever is NOT considered a compliment in the Python culture." For the most part, Perl and Python users differ in their interpretation of these terms and how they are best implemented (see
TIMTOWTDI and
Python philosophy).
Neologisms
A common
neologism in the Python community is
pythonic, which can have a wide range of meanings related to program style. To say that a piece of code is pythonic is to say that it uses Python idioms well; that it is natural or shows fluency in the language. Likewise, to say of an interface or language feature that it is pythonic is to say that it works well with Python idioms; that its use meshes well with the rest of the language.
In contrast, a mark of
unpythonic code is that it attempts to "write C++ (or Lisp, or Perl) code in Python"—that is, provides a rough transcription rather than an idiomatic translation of forms from another language. The concept of pythonicity is tightly bound to Python's minimalistic philosophy of readability - unreadable code or incomprehensible idioms are unpythonic.
Users and admirers of Python—most especially those considered knowledgeable or experienced—are often referred to as
Pythonists,
Pythonistas, and
Pythoneers.
Package naming
The prefix
Py- can be used to show that something is related to Python. Examples of the use of this prefix in names of Python applications or libraries include
Pygame, a binding of
SDL to Python (commonly used to create games);
PyUI, a GUI encoded entirely in Python;
PyQt,
Qt bindings for Python; and PySol, a series of solitaire card games programmed in Python.
Humour
Another important goal of the Python developers is making Python fun to use. This is reflected in the origin of the name (after the television series
Monty Python's Flying Circus), in the common practice of using Monty Python references in example code, and in an occasionally playful approach to tutorials and reference materials. For example, the
metasyntactic variables often used in Python literature are
spam and eggs, instead of the traditional
foo and bar.
*
Comparison of programming languages*
General-purpose dynamic languages*
Free software portal — covers software that's free for users to run, study, modify, and redistribute.
*
Mobile development — How Python mobile stacks up against the alternatives on mobile platforms
*
Python 3000*
The Python Language Reference Manual by Guido van Rossum and Fred L. Drake, Jr. (ISBN 0-9541617-8-5)
*
How to Think Like a Computer Scientist: Learning with Python is an introduction to function-based programming constructs using Python - free download available or hardcopy may be purchased. (ISBN 0971677506)
*
Text Processing in Python by
David Mertz is an intermediate Python book, available both online for free and for money from
Addison-Wesley. (ISBN 0321112547)
*
Python Pocket Reference, Third Edition by Mark Lutz. Updated to cover Python 2.4. Python Pocket Reference 3rd Edition, from
O'Reilly Media. (ISBN 0596009402)
*
Official siteBooks
*
How to Think Like a Computer Scientist: Learning with Python is a good book for people who have never programmed before or people just new to Python.
*
A Byte of Python is a beginner's book on Python.
Dive into Python demonstrates clever and useful Python paradigms for readers who know how to program already. It is
available online, or hardcopy may be purchased.
*
Non-Programmers Tutorial For Python by Josh Cogliati is a beginner's book on Python.
*
Free downloads of Python books*
Python Programming for the Absolute Beginner, Second Edition is an introductory book that uses game programming as its evolving example.
Journals
*
Py, "The Python Online Technical Journal".
Resources
*
Open Directory: Python — Many Python resources.
*
Python FAQTs*
Python Projects and Modules lots of useful code, as well as several articles on Python Programming.
*
The Architecture of Python discusses Python internals.
*
XahLee's-A-Python-A-Day â€" Mailing list with daily examples of Python use. Home page has links to many past tips. Examples given in Python and Perl to help Perl programmers learn Python.
*
Samples to extend and embed Python with C/C++*
Python Bibliotheca — Features video: "Introducing Python" with "A Python Love Story", also books, practice problems, workshops, communities, poetry, all are open content.
*
Learn Python in 10 minutes is a short tutorial/cheatsheet for learning Python if you're already a programmer.
*
Programming Tutorial for the Absolute Beginner. A head start in the coding world with a modern and easy to learn language.
*
Charming Python — Series of articles on Python topics by
David Mertz.
*
Norm Matloff's Quick Python Tutorials — UC Davis Professor Norm Matloff's published Python web resources for his students and Python explorers.
*
Python for Series 60 — Resources for developing in Python on the Nokia Series 60 mobile platform.
*
Python Learning Foundation. — Computer Programming for Everybody.
*
Python411 Podcast Series — The python411 podcasts are created to help people learn Python and learn about Python
*
Useless Python - A repository of Python code, mostly semi-serious or throwaway code that has lived longer than expected.
*
Python 2.4 Quick Reference - Compact overview of the core language features
* An introduction to the principles of object oriented programming -
Introduction to OOP with Python*
Python tutorial screencasts - ShowMeDo videos for installing Python on XP, testing, coding, tools, frameworks and development environments.