-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) 
ross
  • 2,684
  • 2
  • 13
  • 22
  • 2
    Does this answer your question? [Python print statement “Syntax Error: invalid syntax”](https://stackoverflow.com/questions/7584489/python-print-statement-syntax-error-invalid-syntax) – Armali Feb 17 '20 at 13:38

1 Answers1

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) 
Eric Yang
  • 2,678
  • 1
  • 12
  • 18