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

Steven Tagawa
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Steven Tagawa
Python Development Techdegree Graduate 14,438 Points

PEP 8 question on maximum line length

How do you deal with literal strings that go past the maximum line length of 79 characters? For example, say I had a long literal string that I wanted to append to a list:

my_list.append("This is a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, VERY long string...")

Python's implicit continuation inside parentheses doesn't work here, and while a backslash continuation character will work syntactically, any spaces used to indent the following line get inserted into the string.

1 Answer

Grace Kelly
Grace Kelly
33,990 Points

Hi Steven, what I like to do is break the string up onto multiple lines like so:

my_list.append("This is a very, very, very, very, very, very, very, very, "
               "very, very, very, very, very, very, very, very, very, VERY ",
               "long string...")

Just be aware of the spaces when you're breaking up the string :)