JavaRanch Home    
This page:         last edited 27 August 2012         What's Changed?         Edit

Learn Python   

Python is a dynamic object-oriented programming language that can be used for many kinds of software development. It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days. Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code. (shamelessly stolen from the Python home page)

One interesting feature of Python is that it has an interactive console. If python is installed, just type "python" in a shell and start programming:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> i = 5
>>> print i

What strikes most people just starting with Python is that whitespace means something. Rather than using brackets to enclose groups of code, groups of code at the same indent level are grouped. For example, let's declare a function:

>>> def double(x):
...     y = x * x
...     return y
>>> double(2)

To end the function declaration on the interactive console I just hit "enter" on a blank line. Note there's nothing to enclose the work being done in double() except the indent level.

Python has object-oriented features. Without going into too much detail, let's declare a class and access some members:

>>> class Point:
...   def __init__(self, x, y):
...     self.x = x
...     self.y = y
>>> p = Point(1,2)
>>> print p.x
>>> print p.y

Compared to Java, there's a lot of syntax missing. For example, Python does not require that one declares member variables before he uses them. Also, Python also doesn't have the variety of access modifiers that there are in Java.

Language Features

Python doesn't skimp on features:

  • A variety of basic data types are available: numbers (floating point, complex, and unlimited-length long integers), strings (both ASCII and Unicode), lists, and dictionaries.
  • Python supports object-oriented programming with classes and multiple inheritance.
  • Code can be grouped into modules and packages.
  • The language supports raising and catching exceptions, resulting in cleaner error handling.
  • Data types are strongly and dynamically typed. Mixing incompatible types (e.g. attempting to add a string and a number) causes an exception to be raised, so errors are caught sooner.
  • Python contains advanced programming features such as generators and list comprehensions.
  • Python's automatic memory management frees you from having to manually allocate and free memory in your code.
  • Can integrate easily with Java through Jython
  • Python web applications can be built with Zope

Python Documentation

There are plenty of good sources of information on Python. I've found the following to be the most helpful:


JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton