On Fri, Jul 12, 2019 at 11:53:16AM +0000, Shall, Sydney via Tutor wrote:
> Thanks Mike,
> 
> But I am still not clear.

Neither is your question.

> do I write:
> 
> def f([x,y,z]) ?
> How exactly do one write the function and how does one ensure that each 
> positional argument is accounted for.

Is your function taking three seperate arguments, or a single argument 
that must be a list of exactly three items?

(1) Three seperate arguments:

def function(a, b, c):
    # Write the body of the function.
    ...


That's all you need do, as the interpreter will ensure it is only called 
with three arguments.


(2) One list argument with three items:

def function(alist):
    if isinstance(alist, list):
        if len(alist) < 3:
            raise ValueError("too few arguments in alist")
        elif len(alist) > 3:
            raise ValueError("too many arguments in alist")
        else:
            a, b, c = alist  # Unpack the three items from the list.
            # Write the body of the function here.
            ...
    else:
        raise TypeError('expected a list')



Python will ensure your function is only called with a single argument. 
The rest is up to you.




-- 
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to