12/18 Printing out a list item by item in a function



<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
My code works fine, but I have a doubt regarding the output(which did get accepted)

<What do you expect to happen instead?>
I did not expect a None to be printed out in the end.


Replace this line with your code.
n = [3, 5, 7]

def print_list(x):
for i in range(0, len(x)):
print x[i]

print print_list(n)

<do not remove the three backticks above>


by default, a function returns None.

If you put a print statement in front of your function call, the returned result (None) gets printed


What can I add to the return within the function if I wish to actually return nothing at all, like would empty “” return an empty string or nothing at all
n = [3, 5, 7]

def print_list(x):
for i in range(0, len(x)):
print x[i]
return ""
print print_list(n)


you can’t, a function always has to return something

Why would you want to add return statement in your function? The default returned value is fine, if you don’t want to print the returned value, there is an easy solution


That was so dumb of me to use print print_list(n) instead of just calling the function with argument n, thanks for helping me spot it.


very well spotted :slight_smile:

you’re welcome