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)
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)
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)