blob: 481867a6491f040259c5ee2cbe88c1365518b6cb [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001.. _tut-morecontrol:
2
3***********************
4More Control Flow Tools
5***********************
6
7Besides the :keyword:`while` statement just introduced, Python knows the usual
8control flow statements known from other languages, with some twists.
9
10
11.. _tut-if:
12
13:keyword:`if` Statements
14========================
15
16Perhaps the most well-known statement type is the :keyword:`if` statement. For
17example::
18
19 >>> x = int(raw_input("Please enter an integer: "))
Georg Brandl3ce0dee2008-09-13 17:18:11 +000020 Please enter an integer: 42
Georg Brandl8ec7f652007-08-15 14:28:01 +000021 >>> if x < 0:
22 ... x = 0
23 ... print 'Negative changed to zero'
24 ... elif x == 0:
25 ... print 'Zero'
26 ... elif x == 1:
27 ... print 'Single'
28 ... else:
29 ... print 'More'
Georg Brandl3ce0dee2008-09-13 17:18:11 +000030 ...
31 More
Georg Brandl8ec7f652007-08-15 14:28:01 +000032
33There can be zero or more :keyword:`elif` parts, and the :keyword:`else` part is
34optional. The keyword ':keyword:`elif`' is short for 'else if', and is useful
35to avoid excessive indentation. An :keyword:`if` ... :keyword:`elif` ...
Georg Brandlb19be572007-12-29 10:57:00 +000036:keyword:`elif` ... sequence is a substitute for the ``switch`` or
37``case`` statements found in other languages.
Georg Brandl8ec7f652007-08-15 14:28:01 +000038
39
40.. _tut-for:
41
42:keyword:`for` Statements
43=========================
44
45.. index::
46 statement: for
47 statement: for
48
49The :keyword:`for` statement in Python differs a bit from what you may be used
50to in C or Pascal. Rather than always iterating over an arithmetic progression
51of numbers (like in Pascal), or giving the user the ability to define both the
52iteration step and halting condition (as C), Python's :keyword:`for` statement
53iterates over the items of any sequence (a list or a string), in the order that
54they appear in the sequence. For example (no pun intended):
55
Georg Brandlb19be572007-12-29 10:57:00 +000056.. One suggestion was to give a real C example here, but that may only serve to
57 confuse non-C programmers.
Georg Brandl8ec7f652007-08-15 14:28:01 +000058
59::
60
61 >>> # Measure some strings:
62 ... a = ['cat', 'window', 'defenestrate']
63 >>> for x in a:
64 ... print x, len(x)
65 ...
66 cat 3
67 window 6
68 defenestrate 12
69
70It is not safe to modify the sequence being iterated over in the loop (this can
71only happen for mutable sequence types, such as lists). If you need to modify
72the list you are iterating over (for example, to duplicate selected items) you
73must iterate over a copy. The slice notation makes this particularly
74convenient::
75
76 >>> for x in a[:]: # make a slice copy of the entire list
77 ... if len(x) > 6: a.insert(0, x)
78 ...
79 >>> a
80 ['defenestrate', 'cat', 'window', 'defenestrate']
81
82
83.. _tut-range:
84
85The :func:`range` Function
86==========================
87
88If you do need to iterate over a sequence of numbers, the built-in function
89:func:`range` comes in handy. It generates lists containing arithmetic
90progressions::
91
92 >>> range(10)
93 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
94
95The given end point is never part of the generated list; ``range(10)`` generates
96a list of 10 values, the legal indices for items of a sequence of length 10. It
97is possible to let the range start at another number, or to specify a different
98increment (even negative; sometimes this is called the 'step')::
99
100 >>> range(5, 10)
101 [5, 6, 7, 8, 9]
102 >>> range(0, 10, 3)
103 [0, 3, 6, 9]
104 >>> range(-10, -100, -30)
105 [-10, -40, -70]
106
107To iterate over the indices of a sequence, combine :func:`range` and :func:`len`
108as follows::
109
110 >>> a = ['Mary', 'had', 'a', 'little', 'lamb']
111 >>> for i in range(len(a)):
112 ... print i, a[i]
113 ...
114 0 Mary
115 1 had
116 2 a
117 3 little
118 4 lamb
119
120
121.. _tut-break:
122
123:keyword:`break` and :keyword:`continue` Statements, and :keyword:`else` Clauses on Loops
124=========================================================================================
125
126The :keyword:`break` statement, like in C, breaks out of the smallest enclosing
127:keyword:`for` or :keyword:`while` loop.
128
129The :keyword:`continue` statement, also borrowed from C, continues with the next
130iteration of the loop.
131
132Loop statements may have an ``else`` clause; it is executed when the loop
133terminates through exhaustion of the list (with :keyword:`for`) or when the
134condition becomes false (with :keyword:`while`), but not when the loop is
135terminated by a :keyword:`break` statement. This is exemplified by the
136following loop, which searches for prime numbers::
137
138 >>> for n in range(2, 10):
139 ... for x in range(2, n):
140 ... if n % x == 0:
141 ... print n, 'equals', x, '*', n/x
142 ... break
Benjamin Peterson80790282008-08-02 03:05:11 +0000143 ... else:
144 ... # loop fell through without finding a factor
145 ... print n, 'is a prime number'
Georg Brandl8ec7f652007-08-15 14:28:01 +0000146 ...
147 2 is a prime number
148 3 is a prime number
149 4 equals 2 * 2
150 5 is a prime number
151 6 equals 2 * 3
152 7 is a prime number
153 8 equals 2 * 4
154 9 equals 3 * 3
155
156
157.. _tut-pass:
158
159:keyword:`pass` Statements
160==========================
161
162The :keyword:`pass` statement does nothing. It can be used when a statement is
163required syntactically but the program requires no action. For example::
164
165 >>> while True:
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000166 ... pass # Busy-wait for keyboard interrupt (Ctrl+C)
Georg Brandl8ec7f652007-08-15 14:28:01 +0000167 ...
168
Georg Brandla8bb5502008-11-06 18:49:15 +0000169This is commonly used for creating minimal classes like with exceptions, or
170for skipping unwanted exceptions::
171
172 >>> class ParserError(Exception):
173 ... pass
174 ...
175 >>> try:
176 ... import audioop
177 ... except ImportError:
178 ... pass
179 ...
180
181Another place it can be used is as a place-holder for a function or
182conditional body when you are working on new code, allowing you to keep
183thinking at a more abstract level. However, as :keyword:`pass` is silently
184ignored, a better choice may be to raise a :exc:`NotImplementedError`
185exception::
186
187 >>> def initlog(*args):
188 ... raise NotImplementedError # Open logfile if not already open
189 ... if not logfp:
190 ... raise NotImplementedError # Set up dummy log back-end
191 ... raise NotImplementedError('Call log initialization handler')
192 ...
193
194If :keyword:`pass` were used here and you later ran tests, they may fail
195without indicating why. Using :exc:`NotImplementedError` causes this code
196to raise an exception, allowing you to tell exactly where code that you
197need to complete is. Note the two call styles of the exceptions above.
198The comment style is useful in that when you remove the exception you can
199easily leave the comment, which ideally would be a good description for
200the block of code the exception is a placeholder for. The call-style
201will raise a more useful exception however.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000202
203.. _tut-functions:
204
205Defining Functions
206==================
207
208We can create a function that writes the Fibonacci series to an arbitrary
209boundary::
210
211 >>> def fib(n): # write Fibonacci series up to n
212 ... """Print a Fibonacci series up to n."""
213 ... a, b = 0, 1
214 ... while b < n:
215 ... print b,
216 ... a, b = b, a+b
217 ...
218 >>> # Now call the function we just defined:
219 ... fib(2000)
220 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
221
222.. index::
223 single: documentation strings
224 single: docstrings
225 single: strings, documentation
226
227The keyword :keyword:`def` introduces a function *definition*. It must be
228followed by the function name and the parenthesized list of formal parameters.
229The statements that form the body of the function start at the next line, and
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000230must be indented.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000231
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000232The first statement of the function body can optionally be a string literal;
233this string literal is the function's documentation string, or :dfn:`docstring`.
234(More about docstrings can be found in the section :ref:`tut-docstrings`.)
Georg Brandl8ec7f652007-08-15 14:28:01 +0000235There are tools which use docstrings to automatically produce online or printed
236documentation, or to let the user interactively browse through code; it's good
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000237practice to include docstrings in code that you write, so make a habit of it.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000238
239The *execution* of a function introduces a new symbol table used for the local
240variables of the function. More precisely, all variable assignments in a
241function store the value in the local symbol table; whereas variable references
Georg Brandlaa0de3f2008-01-21 16:51:51 +0000242first look in the local symbol table, then in the local symbol tables of
243enclosing functions, then in the global symbol table, and finally in the table
244of built-in names. Thus, global variables cannot be directly assigned a value
245within a function (unless named in a :keyword:`global` statement), although they
246may be referenced.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000247
248The actual parameters (arguments) to a function call are introduced in the local
249symbol table of the called function when it is called; thus, arguments are
250passed using *call by value* (where the *value* is always an object *reference*,
251not the value of the object). [#]_ When a function calls another function, a new
252local symbol table is created for that call.
253
254A function definition introduces the function name in the current symbol table.
255The value of the function name has a type that is recognized by the interpreter
256as a user-defined function. This value can be assigned to another name which
257can then also be used as a function. This serves as a general renaming
258mechanism::
259
260 >>> fib
261 <function fib at 10042ed0>
262 >>> f = fib
263 >>> f(100)
264 1 1 2 3 5 8 13 21 34 55 89
265
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000266Coming from other languages, you might object that ``fib`` is not a function but
267a procedure since it doesn't return a value. In fact, even functions without a
268:keyword:`return` statement do return a value, albeit a rather boring one. This
269value is called ``None`` (it's a built-in name). Writing the value ``None`` is
270normally suppressed by the interpreter if it would be the only value written.
271You can see it if you really want to using :keyword:`print`::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000272
Georg Brandl706132b2007-10-30 17:57:12 +0000273 >>> fib(0)
Georg Brandl8ec7f652007-08-15 14:28:01 +0000274 >>> print fib(0)
275 None
276
277It is simple to write a function that returns a list of the numbers of the
278Fibonacci series, instead of printing it::
279
280 >>> def fib2(n): # return Fibonacci series up to n
281 ... """Return a list containing the Fibonacci series up to n."""
282 ... result = []
283 ... a, b = 0, 1
284 ... while b < n:
285 ... result.append(b) # see below
286 ... a, b = b, a+b
287 ... return result
288 ...
289 >>> f100 = fib2(100) # call it
290 >>> f100 # write the result
291 [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
292
293This example, as usual, demonstrates some new Python features:
294
295* The :keyword:`return` statement returns with a value from a function.
296 :keyword:`return` without an expression argument returns ``None``. Falling off
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000297 the end of a function also returns ``None``.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000298
299* The statement ``result.append(b)`` calls a *method* of the list object
300 ``result``. A method is a function that 'belongs' to an object and is named
301 ``obj.methodname``, where ``obj`` is some object (this may be an expression),
302 and ``methodname`` is the name of a method that is defined by the object's type.
303 Different types define different methods. Methods of different types may have
304 the same name without causing ambiguity. (It is possible to define your own
305 object types and methods, using *classes*, as discussed later in this tutorial.)
306 The method :meth:`append` shown in the example is defined for list objects; it
307 adds a new element at the end of the list. In this example it is equivalent to
308 ``result = result + [b]``, but more efficient.
309
310
311.. _tut-defining:
312
313More on Defining Functions
314==========================
315
316It is also possible to define functions with a variable number of arguments.
317There are three forms, which can be combined.
318
319
320.. _tut-defaultargs:
321
322Default Argument Values
323-----------------------
324
325The most useful form is to specify a default value for one or more arguments.
326This creates a function that can be called with fewer arguments than it is
327defined to allow. For example::
328
329 def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
330 while True:
331 ok = raw_input(prompt)
332 if ok in ('y', 'ye', 'yes'): return True
333 if ok in ('n', 'no', 'nop', 'nope'): return False
334 retries = retries - 1
335 if retries < 0: raise IOError, 'refusenik user'
336 print complaint
337
338This function can be called either like this: ``ask_ok('Do you really want to
339quit?')`` or like this: ``ask_ok('OK to overwrite the file?', 2)``.
340
341This example also introduces the :keyword:`in` keyword. This tests whether or
342not a sequence contains a certain value.
343
344The default values are evaluated at the point of function definition in the
345*defining* scope, so that ::
346
347 i = 5
348
349 def f(arg=i):
350 print arg
351
352 i = 6
353 f()
354
355will print ``5``.
356
357**Important warning:** The default value is evaluated only once. This makes a
358difference when the default is a mutable object such as a list, dictionary, or
359instances of most classes. For example, the following function accumulates the
360arguments passed to it on subsequent calls::
361
362 def f(a, L=[]):
363 L.append(a)
364 return L
365
366 print f(1)
367 print f(2)
368 print f(3)
369
370This will print ::
371
372 [1]
373 [1, 2]
374 [1, 2, 3]
375
376If you don't want the default to be shared between subsequent calls, you can
377write the function like this instead::
378
379 def f(a, L=None):
380 if L is None:
381 L = []
382 L.append(a)
383 return L
384
385
386.. _tut-keywordargs:
387
388Keyword Arguments
389-----------------
390
391Functions can also be called using keyword arguments of the form ``keyword =
392value``. For instance, the following function::
393
394 def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
395 print "-- This parrot wouldn't", action,
396 print "if you put", voltage, "volts through it."
397 print "-- Lovely plumage, the", type
398 print "-- It's", state, "!"
399
400could be called in any of the following ways::
401
402 parrot(1000)
403 parrot(action = 'VOOOOOM', voltage = 1000000)
404 parrot('a thousand', state = 'pushing up the daisies')
405 parrot('a million', 'bereft of life', 'jump')
406
407but the following calls would all be invalid::
408
409 parrot() # required argument missing
410 parrot(voltage=5.0, 'dead') # non-keyword argument following keyword
411 parrot(110, voltage=220) # duplicate value for argument
412 parrot(actor='John Cleese') # unknown keyword
413
414In general, an argument list must have any positional arguments followed by any
415keyword arguments, where the keywords must be chosen from the formal parameter
416names. It's not important whether a formal parameter has a default value or
417not. No argument may receive a value more than once --- formal parameter names
418corresponding to positional arguments cannot be used as keywords in the same
419calls. Here's an example that fails due to this restriction::
420
421 >>> def function(a):
422 ... pass
423 ...
424 >>> function(0, a=0)
425 Traceback (most recent call last):
426 File "<stdin>", line 1, in ?
427 TypeError: function() got multiple values for keyword argument 'a'
428
429When a final formal parameter of the form ``**name`` is present, it receives a
430dictionary (see :ref:`typesmapping`) containing all keyword arguments except for
431those corresponding to a formal parameter. This may be combined with a formal
432parameter of the form ``*name`` (described in the next subsection) which
433receives a tuple containing the positional arguments beyond the formal parameter
434list. (``*name`` must occur before ``**name``.) For example, if we define a
435function like this::
436
437 def cheeseshop(kind, *arguments, **keywords):
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000438 print "-- Do you have any", kind, "?"
Georg Brandl8ec7f652007-08-15 14:28:01 +0000439 print "-- I'm sorry, we're all out of", kind
440 for arg in arguments: print arg
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000441 print "-" * 40
Georg Brandl8ec7f652007-08-15 14:28:01 +0000442 keys = keywords.keys()
443 keys.sort()
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000444 for kw in keys: print kw, ":", keywords[kw]
Georg Brandl8ec7f652007-08-15 14:28:01 +0000445
446It could be called like this::
447
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000448 cheeseshop("Limburger", "It's very runny, sir.",
Georg Brandl8ec7f652007-08-15 14:28:01 +0000449 "It's really very, VERY runny, sir.",
Georg Brandl8ec7f652007-08-15 14:28:01 +0000450 shopkeeper='Michael Palin',
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000451 client="John Cleese",
452 sketch="Cheese Shop Sketch")
Georg Brandl8ec7f652007-08-15 14:28:01 +0000453
454and of course it would print::
455
456 -- Do you have any Limburger ?
457 -- I'm sorry, we're all out of Limburger
458 It's very runny, sir.
459 It's really very, VERY runny, sir.
460 ----------------------------------------
461 client : John Cleese
462 shopkeeper : Michael Palin
463 sketch : Cheese Shop Sketch
464
465Note that the :meth:`sort` method of the list of keyword argument names is
466called before printing the contents of the ``keywords`` dictionary; if this is
467not done, the order in which the arguments are printed is undefined.
468
469
470.. _tut-arbitraryargs:
471
472Arbitrary Argument Lists
473------------------------
474
Andrew M. Kuchling3822af62008-04-15 13:10:07 +0000475.. index::
476 statement: *
477
Georg Brandl8ec7f652007-08-15 14:28:01 +0000478Finally, the least frequently used option is to specify that a function can be
479called with an arbitrary number of arguments. These arguments will be wrapped
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000480up in a tuple (see :ref:`tut-tuples`). Before the variable number of arguments,
481zero or more normal arguments may occur. ::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000482
Benjamin Petersondee01d82008-05-28 11:51:41 +0000483 def write_multiple_items(file, separator, *args):
484 file.write(separator.join(args))
Georg Brandl8ec7f652007-08-15 14:28:01 +0000485
486
487.. _tut-unpacking-arguments:
488
489Unpacking Argument Lists
490------------------------
491
492The reverse situation occurs when the arguments are already in a list or tuple
493but need to be unpacked for a function call requiring separate positional
494arguments. For instance, the built-in :func:`range` function expects separate
495*start* and *stop* arguments. If they are not available separately, write the
496function call with the ``*``\ -operator to unpack the arguments out of a list
497or tuple::
498
499 >>> range(3, 6) # normal call with separate arguments
500 [3, 4, 5]
501 >>> args = [3, 6]
502 >>> range(*args) # call with arguments unpacked from a list
503 [3, 4, 5]
504
Andrew M. Kuchling3822af62008-04-15 13:10:07 +0000505.. index::
506 statement: **
507
Georg Brandl8ec7f652007-08-15 14:28:01 +0000508In the same fashion, dictionaries can deliver keyword arguments with the ``**``\
509-operator::
510
511 >>> def parrot(voltage, state='a stiff', action='voom'):
512 ... print "-- This parrot wouldn't", action,
513 ... print "if you put", voltage, "volts through it.",
514 ... print "E's", state, "!"
515 ...
516 >>> d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"}
517 >>> parrot(**d)
518 -- This parrot wouldn't VOOM if you put four million volts through it. E's bleedin' demised !
519
520
521.. _tut-lambda:
522
523Lambda Forms
524------------
525
526By popular demand, a few features commonly found in functional programming
527languages like Lisp have been added to Python. With the :keyword:`lambda`
528keyword, small anonymous functions can be created. Here's a function that
529returns the sum of its two arguments: ``lambda a, b: a+b``. Lambda forms can be
530used wherever function objects are required. They are syntactically restricted
531to a single expression. Semantically, they are just syntactic sugar for a
532normal function definition. Like nested function definitions, lambda forms can
533reference variables from the containing scope::
534
535 >>> def make_incrementor(n):
536 ... return lambda x: x + n
537 ...
538 >>> f = make_incrementor(42)
539 >>> f(0)
540 42
541 >>> f(1)
542 43
543
544
545.. _tut-docstrings:
546
547Documentation Strings
548---------------------
549
550.. index::
551 single: docstrings
552 single: documentation strings
553 single: strings, documentation
554
555There are emerging conventions about the content and formatting of documentation
556strings.
557
558The first line should always be a short, concise summary of the object's
559purpose. For brevity, it should not explicitly state the object's name or type,
560since these are available by other means (except if the name happens to be a
561verb describing a function's operation). This line should begin with a capital
562letter and end with a period.
563
564If there are more lines in the documentation string, the second line should be
565blank, visually separating the summary from the rest of the description. The
566following lines should be one or more paragraphs describing the object's calling
567conventions, its side effects, etc.
568
569The Python parser does not strip indentation from multi-line string literals in
570Python, so tools that process documentation have to strip indentation if
571desired. This is done using the following convention. The first non-blank line
572*after* the first line of the string determines the amount of indentation for
573the entire documentation string. (We can't use the first line since it is
574generally adjacent to the string's opening quotes so its indentation is not
575apparent in the string literal.) Whitespace "equivalent" to this indentation is
576then stripped from the start of all lines of the string. Lines that are
577indented less should not occur, but if they occur all their leading whitespace
578should be stripped. Equivalence of whitespace should be tested after expansion
579of tabs (to 8 spaces, normally).
580
581Here is an example of a multi-line docstring::
582
583 >>> def my_function():
584 ... """Do nothing, but document it.
585 ...
586 ... No, really, it doesn't do anything.
587 ... """
588 ... pass
589 ...
590 >>> print my_function.__doc__
591 Do nothing, but document it.
592
593 No, really, it doesn't do anything.
594
595
Georg Brandl35f88612008-01-06 22:05:40 +0000596.. _tut-codingstyle:
597
598Intermezzo: Coding Style
599========================
600
601.. sectionauthor:: Georg Brandl <georg@python.org>
602.. index:: pair: coding; style
603
604Now that you are about to write longer, more complex pieces of Python, it is a
605good time to talk about *coding style*. Most languages can be written (or more
606concise, *formatted*) in different styles; some are more readable than others.
607Making it easy for others to read your code is always a good idea, and adopting
608a nice coding style helps tremendously for that.
609
Andrew M. Kuchling8c65b1e2008-04-15 13:10:41 +0000610For Python, :pep:`8` has emerged as the style guide that most projects adhere to;
Georg Brandl35f88612008-01-06 22:05:40 +0000611it promotes a very readable and eye-pleasing coding style. Every Python
612developer should read it at some point; here are the most important points
613extracted for you:
614
615* Use 4-space indentation, and no tabs.
616
617 4 spaces are a good compromise between small indentation (allows greater
618 nesting depth) and large indentation (easier to read). Tabs introduce
619 confusion, and are best left out.
620
621* Wrap lines so that they don't exceed 79 characters.
622
623 This helps users with small displays and makes it possible to have several
624 code files side-by-side on larger displays.
625
626* Use blank lines to separate functions and classes, and larger blocks of
627 code inside functions.
628
629* When possible, put comments on a line of their own.
630
631* Use docstrings.
632
633* Use spaces around operators and after commas, but not directly inside
634 bracketing constructs: ``a = f(1, 2) + g(3, 4)``.
635
636* Name your classes and functions consistently; the convention is to use
637 ``CamelCase`` for classes and ``lower_case_with_underscores`` for functions
Georg Brandl3ce0dee2008-09-13 17:18:11 +0000638 and methods. Always use ``self`` as the name for the first method argument
639 (see :ref:`tut-firstclasses` for more on classes and methods).
Georg Brandl35f88612008-01-06 22:05:40 +0000640
641* Don't use fancy encodings if your code is meant to be used in international
642 environments. Plain ASCII works best in any case.
643
Georg Brandl8ec7f652007-08-15 14:28:01 +0000644
645.. rubric:: Footnotes
646
Georg Brandl35f88612008-01-06 22:05:40 +0000647.. [#] Actually, *call by object reference* would be a better description,
648 since if a mutable object is passed, the caller will see any changes the
649 callee makes to it (items inserted into a list).
Georg Brandl8ec7f652007-08-15 14:28:01 +0000650