Python Universe Builder

Python Essentials

Python is a full language, used to build web servers, browsers, databases, utilities, and yes, even games. There is a wealth of documentation and examples available on the web. This page doesn't even scratch the surface -- but perhaps it will be enough to get you started, or serve as a quick reference for commonly needed syntax. For more detail, consult the Python documentation.

Datatypes

42                              # an integer
42.0                            # a real number
'wow' or "wow"                  # a string
[1,5,7,9]                       # a list
mylist[0]                       # the first element of list mylist
{1:'one',42:'life'}             # a dictionary (maps 1 to 'one', etc.)

Assignments

this = that                     # assign this the value of that
ultimateAnswer = 42             # store 42 in variable ultimateAnswer
kitten = Kitten("Fluffy")       # create a new Kitten, and store it in kitten
name = kitten.GetName()         # store kitten's current name in name
a,b,c = 1,2,3                   # multiple assignments at once

Function Calls

isString('wow')                 # evaluates to 1 if 'wow' is a string (it is)
myObject.DoSomething()          # call myObject's DoSomething() method
Note: Class functions (methods) are defined with the first parameter specified, e.g. def GetName(self), but called with the object name before the method name, e.g. self.GetName() .


http://www.strout.net/python/pub/doc/python.htm
Last Modified: 5/08/96 . . . . . . Joe Strout . . . joe@strout.net