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

Susan Rodgers
Susan Rodgers
6,346 Points

I have a general Python question - why bother with 'format' when you can just concatenate text and variables.

... python3

name = "Susan" print ("My name is " + name) My name is Susan

print ("My name is {}".format (name)) My name is Susan ...

2 Answers

Kiefer H
Kiefer H
5,665 Points

I sometimes wonder why we use .format() at all when you just can f'{}'

Formatted strings just look better, and convey information a whole easier.

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

That's a definitely fair question to ask.

You may run into a scenario where you have been asked to write a program that can run on different platforms (with the same code base). For example-- if you target only platforms that are running Python 3.6 and greater, then you can write f-strings -- earlier versions, unfortunately, aren't f-string aware.

As an aspirant-- often your first job might be maintenance of existing code. So you will definitely have to be familiar .format() and % operator as well as string concatenation.

Good luck with your Python journey!