1

I seem to be somehow screwing up the most basic thing. I have:

def function(a, b, c):
    return 'hi'

print(function(a,b,c)) results in a NameError for every variable.

What is the cause of this?

1 Answer 1

8

The names of the arguments of a function are local variables, they are not available as global names. a, b and c exist only inside of the function, and receive the values you pass to the function.

You need to create new variables or use literal values when calling the function:

print(function(1, 2, 3))

would work because 1, 2 and 3 are actual values to pass into the function.

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

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.