-1

I'm starting to learn list.append by passing a string to the parameter in the function, However I'm getting an error, how can I solve this issue?

Here's my code:

def add_more(name):
    name.append(5)

name=[1,2,3,4]
print add_more(name) 
3

1 Answer 1

0

While the variable name does get altered as a pass by reference, if you're going to print it out, you'll need to add a return statement to your function

def add_more(name):
    name.append(5)
    return name

name=[1,2,3,4] 
print add_more(name) 
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.