[Tutor] Why are expressions not allowed as parameters in function definition statements?

boB Stepp robertvstepp at gmail.com
Sat Jun 18 16:33:35 EDT 2016


On Sat, Jun 18, 2016 at 3:14 PM, Joel Goldstick
<joel.goldstick at gmail.com> wrote:
> On Sat, Jun 18, 2016 at 3:04 PM, boB Stepp <robertvstepp at gmail.com> wrote:

>> Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900
>> 64 bit (AMD64)] on win32
>> Type "help", "copyright", "credits" or "license" for more information.
>> py3: def d(row, col/2, radius=5):
>>   File "<stdin>", line 1
>>     def d(row, col/2, radius=5):
>>                   ^
>> SyntaxError: invalid syntax
>>
>> And this surprised me.  It seems that only identifiers are allowed as
>> parameters in a function definition statement, and I cannot help but
>> wonder why?  It seems that in most other places in Python's syntax it
>> will allow one to insert almost any kind of object or expression.

> I'll take a stab.  The function is defined once.  The parameters name
> the arguments to be passed when the function is invoked.  They can
> have defaults, but you are asking it to perform a calculation, which
> would only be done when the function is defined.

In retrospect, I probably should have figured this out.  I know that
defaults to parameters are assigned at function definition time and
that arguments only get passed at function call time.  If I use an
expression, at function definition time there is no value to assign.
So as long as Python uses this mechanism for handling function
definition, I now don't see how expressions can be usable as
parameters.

Thanks Joel!

boB


More information about the Tutor mailing list