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?

asked Apr 19, 2015 at 2:15

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.

answered Apr 19, 2015 at 2:17
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.