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


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/lists-and-functions/exercises/printing-out-a-list-item-by-item-in-a-function?action=lesson_resume

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

```python

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>

#2

by default, a function returns None.

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


#3

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)


#4

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


#5

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.


#6

very well spotted :slight_smile:

you’re welcome


#7