Python!
http://www.python.org
(Yes, it is named for Monty Python)
Python Hello World
>>> def hello():
... print "Hello, World!"
...
>>> hello()
Hello, World!
Data Types in Python
Strings
>>> word = 'Help'+'A'
>>> word
'HelpA'
>>> '<'+ word*5 + '>'
'<HelpAHelpAHelpAHelpAHelpA>'
Lists
>>> a = ['spam','eggs',[1,2],4]
>>> a
['spam', 'eggs', [1, 2], 4]
>>> a[0]
'spam'
>>> a[1:]
['eggs', [1, 2], 4]
>>> a[2]
[1, 2]
Dictionaries
>>> d={}
>>> d['fred']=1234
>>> d['george']=5432
>>> d
{'fred': 1234, 'george': 5432}
>>> d['george']
5432
Control structures in Python
>>> for i in a:
... print i
...
spam
eggs
[1, 2]
4
>>> for i in range(2,4):
... print i
...
2
3
Modules
Like Java's packages
import sys
sys.exit()
from sys, urllib import *
urlretrieve('http://www.cc.gatech.edu')
Exceptions
>>> numbers = [0.333, 2.5, 0, 10]
>>> for x in numbers:
... print x,
... try:
... print 1.0 / x
... except ZeroDivisionError:
... print '*** has no inverse ***'
...
0.333 3.003003003
2.5 0.4
0 *** has no inverse ***
10 0.1
Classes in Python
All functions are ìvirtualî
class MyClass:
i = 12345
def f(self):
return 'hello world'+str(self.i)
def __init__(self):
self.name='Mud'
x=MyClass()
x.f()
class MySecondClass(MyClass,YourClass):
def __init__(self):
self.address='Somehwere'
MyClass.__init__()
Odds & Ends on Python
Can do operator overloading
No class methods or data
HUGE library: Persistent objects, several UI libraries, HTML parsers, URL tools, image processing, etc.
Runs on just about anything