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) Ins & Outs String Formatting

formatting

Didn't see much of a difference from the last video to now when inserting the format brackets.

1 Answer

Hi Angelo

The difference between string concatenation and the format method is that format method allows you to be more precise with where your variables are put into a given string .

my_age =35
my_height = 5.8

ordinarily with string concatenation i would have to return "My age is "+my_age+" and my height is "+my_height;. In this example you would have to make sure you your spacing between variable are correct and so on in order for the string to display correctly.

The format method makes still very easy by just return the string as you would type it out replacing your variables {} in the string.

return "My age is {} and my height is {}".format(str(my_age),str(my_height)). 

This way is far more simple then doing string concatination. hope this helps