list = [1, 2, 3, -4.3, "blah", ['a', 'b', 'c']]Many operations can be performed on lists:
list.append('a')
is equivalent to:
list + ['a']
tuple = (x, y)Tuples are like lists, except that once an instance has been created, it cannot be changed. The most common use of tuples is in making functions return more than one value:
return (a, b)In fact, there is a short hand for tuples that makes this look even better:
return a, bNeat, huh?
dict = {'feffi': 'feffi@hotmail.com', 'munchkin': 'munchkin@humbug.org'}
dict['feffi']
outputs:
'feffi@hotmail.com'There are a few operations defined for dictionaries:
Now to show how to pass arbitrary arguments to a function. If a function is defined thus:
def function(args**):
print args
and call it like this:
function(foo='bar', bar='baz')then it will output:
{'foo': 'bar', 'bar': 'baz'}