Is there a clean way to write multi-lines strings in Python?
python, python-2.7
Solution
You can try:
string = "sdfsdfsdfsdfsdf" \
"sdfsdfsdfsdfs"
And the result:
>>> string
'sdfsdfsdfsdfsdfsdfsdfsdfsdfs'
The same effect can be achieved by using paranthesis instead of `\`, as @Nigel Tufnel mentioned in his answer.
Problem
It sounds like a beginner question, but I never succeeded in writing long strings in a clean way in Python. Here are the 4 ways I listed to do it. None of them seems ok to me. ``` def useless_func(): # WRONG WAY A : string_A displays well but breaks the 80 char max PEP 8 recommandation string_A = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." # WRONG WAY B : string_B will create unwanted spaces between word 'sed' and 'do' when printed string_B = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed\ do eiusmod tempor incididunt ut labore et dolore magna aliqua." # WRONG WAY C : string_C displays well but makes my code ugly because it breaks indentation string_C = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed\ do eiusmod tempor incididunt ut labore et dolore magna aliqua." # WRONG WAY D : string_D (triples quotes) has the same problem than string_B (unwanted spaces) string_D = '''Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.''' ``` Am I missing something?