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

Mark Nembhard
Mark Nembhard
1,387 Points

How do you return both the string as well as the parameter value

I get returning a value but not the string as well as the parameter. Seems straightforward but it does not follow from what i have been shown so far

Hi Mark.

You're going to want to concatenate the parameter and the string "Hello" before returning. Here's a possible solution:

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

In this example, you pass 'name' as an argument, then concatenate (adding strings together) "Hello " and passed-in value. By doing this, you're creating and returning a single string with the value "Hello [name]". Does this make sense?

Mark Nembhard
Mark Nembhard
1,387 Points

Thanks so much. It makes sense although I think with the return keyword it wasn't explicitly stated that you can perform concatenation on a returned value. I take it you can apply any form of mathematical operation on a returned value then? As in return (x/100*2) ^2?

1 Answer

Steven Parker
Steven Parker
231,269 Points

You can use any kind of expression in a "return" statement. It can involve math, call other functions, or some combination of both.