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 Types and Branching String Methods

Yaz R
seal-mask
.a{fill-rule:evenodd;}techdegree
Yaz R
Python Web Development Techdegree Student 1,262 Points

After printing my string, how would i be able to add spaces without having to type the long string all over again?

This is my code:

learning="I love to learn many languages " learning.upper() 'I LOVE TO LEARN MANY LANGUAGES'

Now, what if I wanted to add spaces (escape sequence \n) anywhere in between the string, without having to type the string all over again?

blank_str = " " print("I love learning {} languages".format(blank_str*20))

1 Answer

Steven Parker
Steven Parker
229,005 Points

Strings are immutable, but you can replace it with a new string made using portions of the existing one:

learning = "I love to learn many languages"
learning = learning[:15] + "\n" + learning[16:]
print(learning)

I love to learn
many languages