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 (2015) Python Data Types String Formatting

Sun Min
Sun Min
2,941 Points

for spacing in Python

Hi

I'am working on Python basics right now and I was working on the code challenges.

and my challenge was

OK, so now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the variable subject again.

this, and I did

name = "me"

subject = "Treehouse loves {} " .format(name)

and i got wrong answer.

because i have space between .format

and I check after erase space and it said correct.

so my question is. i need to care about every single spaces on my code? because some code is okay if put space but some code doesn't :(

strings.py
name = "sun"

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! It depends entirely on where the space is. But yes, when using a method such as .format()it may not have a space between the string and the invocation of the method. If your space is inside a string, it won't matter. And yes, you will find that capitalization, punctuation, and spacing are very important in programming languages. However, this has the added benefit of making you rather detail-oriented!

Happy coding! :sparkles:

Sun Min
Sun Min
2,941 Points

Thank you Jennifer!

I should be more detail oriented! :)