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 Python Basics Functions and Looping Functions

Fabian Timm
Fabian Timm
624 Points

Why don't we have to find unique names for the 3 variables called "result"?

In the first part of the video phrases offering "praise", "advice" and "advice2" are all printed referring to the variabe "result".

Why is it clear, which "result" the code is referring to? Why doesn't the result of "praise" just get printed three times, for example?

2 Answers

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

In the praise section, Craig is creating the result variable and setting it equal to praise. In the next section, the result variable is overwritten to now equal advice and then at the end it is overwritten again to equal advice2. So the result variable's content changes each time it is overwritten. You overwrite a variable by setting it equal to something else.

In a big project, you're right, you would probably want to use different variable names in case you wanted to use the praise result again in another way.

Fabian Timm
Fabian Timm
624 Points

Thank you, I get it now.