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 Sequences Sequence Operations Concatenation and Multiplication

Leah Kelly
Leah Kelly
4,141 Points

str looks like a function, so why is it acting like a variable?

Ashley uses str (which I think is a function) as a variable. Why is it acting like a variable?

3 Answers

Steven Parker
Steven Parker
231,268 Points

In the video, the instructor creates a variable named "str". This replaces the built-in function that normally has that name, but it's not a problem here since the function is not being used.

It is, however, a questionable choice for a variable name for the very reason that it "shadows" the common function (makes it not usable). In general, the "best practice" would be to always choose variable names that do not conflict with any common system resources.

Leah Kelly
Leah Kelly
4,141 Points

Thanks! Before, I didn’t think I could use functions as variables.

Steven Parker
Steven Parker
231,268 Points

No function is being used here. The identifier "str" is being used solely as a variable. Now, normally it would have been a system-defined function, but that function is no longer accessible after the variable is created.

Leah Kelly
Leah Kelly
4,141 Points

Ok, so they were only using what WOULD HAVE BEEN a function. Thanks again.