DEV Community

loading...

Discussion on: How To Write Clean Code in Python

hanpari profile image
Pavel Morava • Edited

Well, Python helps you split the line in the following fashion:


long_line = (
    "This is a very very very "
    "very very very very very very very "
    "very very very very very very very "
    "very very very very very long line."
    )

print(long_line)

>>> print(long_line)
This is a very very very very very very very very very very very very very very very very very very very very very very long line.

Enter fullscreen mode Exit fullscreen mode

Not sure how often you need long string lines, but you can split a string like this.
Despite more laborious, the result seems more readable to me.

Thread Thread
victorsgb profile image
victorsgb

This is quite useful! Thanks for sharing!

Thread Thread
hanpari profile image
Pavel Morava

You are welcome. By the way, note there is no concatenating operator between lines. The main difference between this and triple quotes strings is that there is no end of line character introduced unless typed explicitly.

Thread Thread
jerrynsh profile image
Jerry Ng Author

The code snippet that you provide is super helpful! Thanks for sharing it!

Thread Thread
hanpari profile image
Pavel Morava

Glad it is useful. I've collected plenty of little tricks and tips over the time, and I keep forgetting them regularly.

Whoever reads this and have a question, ask and I may perhaps recall another one 😀