Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

returning vs. printing a value in functions in Python

When I print a parameter in a function, I receive a strange None at the end. What's reason? Example:

def packer (*args):
    for val in args:
        print (val)
print (packer('i','love','you'))

Result looks like this:

 i
love
you
None

2 Answers

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi Mark Maksi ! You are getting the None because you are also printing your function call print(packer('i','love','you')). If you just call the function on its own you won't see the None like this: packer('i','love','you'). This is because you've told Python to print the function too which typically prints whatever is returned from a function but you aren't returning anything so there is nothing to print, or None.

Megan Amendola Thank you! It worked as you said. <3