Mr. Kennedy Mr. Kennedy - 2 years ago 70
Python Question

Are Python function parameters enclosed in tuples or just conventional parentheses?

Are functions passed parameters enclosed in parentheses because they are handled as tuples, or just a result of f(x) convention?

i.e. is (b, a, r) a tuple here:

def foo(b, a, r):

Or, is it something more like the way parentheses are used in math equations, e.g.

>>> 3 * 2 + 1
>>> 3 * (2 + 1)

Answer Source

You can answer this by looking at the Python Grammar.

The relevant lines are:

funcdef: 'def' NAME parameters ['->' test] ':' suite
parameters: '(' [typedargslist] ')'

So in your example, the grammar would say that (b, a, r) is a typedargslist surrounded by brackets.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download