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 (Retired) Things That Count Things That Count

Jing Zhi Tay
Jing Zhi Tay
571 Points

How do i add a string version of a variable? what does that even mean?

what does this mean?

days_alive.py
age = 21
days = (age*52*7)
estimate = round(days)
summary = 

2 Answers

Adding to Michael's answer. Almost all values can be a string or some other type. For example:

"this is a string"
this_is_a_variable = "Which holds the value of this string."
23 # this is a number
"23" # this is a string

However in the current question, it's asking you to put the variable into a string.

summary = "I am {} days old!"

To understand this, you need to review the ".format" method for strings. The format method allows you to place values within strings (sometimes called string interpolation) without having to explicitly change the type of the input. So now with that information, you can do the following:

summary = "I am {} days old".format(estimate)

Check out the ".format" method and be sure to get it down since you'll be using it pretty often.

Hope this helps!

Michael Joyce
Michael Joyce
6,214 Points

If you want to change an integer into a string you need to wrap it in a str() method. Try summary = str(estimate). By using str() you are changing estimate into a string. Keep in mind you can no longer perform calculations etc.