Search code examples
pythonlistfunctionreturn

Return items from list in function. Python


my_list = ['a','b','c']

def func(input):
    for i in input:
        print i
print func(my_list)

Output

a
b
c
None

I don't want the 'None' so how I can do a single line of code to return the items in my input list?

I tried:

return for i in input: print i

but it didn't work because return statements don't work like that


Solution

  • You are printing the return code from func which is none. Just call func(my_list) without the print.