11.5.1. Positional Arguments

These are the standard vanilla parameters that we are all familiar with. Positional arguments must be passed in the exact order that they are defined for the functions that are called. Also, without the presence of any default arguments (see next section), the exact number of arguments passed to a function (call) must be exactly the number declared:

>>> def foo(who):       # defined for only 1 argument
…       print 'Hello', who … >>> foo() # 0 arguments… BAD Traceback (innermost last): File "<stdin>", line 1, in ? TypeError: not enough arguments; expected 1, got 0 >>> >>> foo('World!') # 1 argument… WORKS Hello World! >>> >>> foo('Mr.', 'World!')# 2 arguments… BAD Traceback (innermost last): File "<stdin>", line 1, in ? TypeError: ...

Get Core Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.