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 Functions, Packing, and Unpacking Getting Info In and Out of Functions Functions with Arguments and Returns

Marlon Jay Chua
Marlon Jay Chua
4,281 Points

Cannot understand challenge task 2 of 2 on creating_functions.py. Please help.

I'm confused with assigning a variable on the return value, I already did on task 1 of 2. Please help. Thanks.

creating_functions.py
def hello_student(name):
    var = 'Hello ' + name
    return var

hello_student()

1 Answer

You'll need to save the return value of the function to a variable named hello, like so:

def hello_student(name):
    var = 'Hello ' + name
    return var

hello = hello_student('your name')

You can also return the value without declaring another variable inside the function:

def hello_student(name):
    return 'Hello ' + name

hello = hello_student('your name')