0

Why doesn't this work? What would it take for this to work?

call = 'Duster'
def text(call):
 print(call)
text()
Prune
78k14 gold badges63 silver badges83 bronze badges
asked Nov 16, 2016 at 23:40

2 Answers 2

4

The call inside your function and call outside your function are utterly independent variables. You have to pass things through the parameter list.

call = 'Duster'
def text(call):
 print(call)
text(call)

Actually, you can use a global variable, but please avoid those.

To illustrate this better, move the lines of your main program together and change the names:

def text(phrase):
 print(phrase)
name = 'Duster'
text(name)

Also, the main program of two lines could be just one line:

text('Duster')
answered Nov 16, 2016 at 23:41
Sign up to request clarification or add additional context in comments.

Comments

1

It doesn't work because the argument named call takes precedence over the variable named call due to scoping.

You could make this work by using your code and just changing the last line

text(call)

Or you could use the variable directly and not an argument

call = 'Duster'
def text():
 print(call)
text()
answered Nov 16, 2016 at 23:43

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.