0

Example:

def somerando(a,b,c,d):
    if not a+b+c+d == 9000:
        return (a+b+c+d)

somerando(1,2,3,4)

Returns: 10

but

randonumbs = [1,2,3,4]

somerando(randonumbs)

Gives the following error:

TypeError Traceback (most recent call last) in ----> 1 somerando(randonumbs)

TypeError: somerando() missing 3 required positional arguments: 'b', 'c', and 'd'

3 Answers 3

1

your function expects 4 arguments. randonumbs = [1,2,3,4] is a list (of four items); that is one argument for your function.

you could do this:

randonumbs = [1,2,3,4]
somerando(*randonumbs)

this usage of the asterisk (*) is discussed in this question or in PEP 3132.

Sign up to request clarification or add additional context in comments.

Comments

0

You passed randonumbs as list, means this whole list is considered as first argument to the function somerando
You can use somerando(*randonumbs) .

Here, * means pass as tuple & ** means pass as dictionary (key, value pair) if you use ** in function parameters/ arguments.


Thank you.

Comments

0

The single-asterisk form of *args can be used as a parameter to send a non-keyworded variable-length argument list to functions, like below

randonumbs = [1,2,3,4]
somerando(*randonumbs)

The double asterisk form of **kwargs is used to pass a keyworded, variable-length argument dictionary to a function.

randonumbs = {'a':1, 'b':2, 'c': 3, 'd': 4}
somerando(**randonumbs)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.