Asked • 03/19/19

Pythonic way to create a long multi-line string?

I have a very long query. I would like to split it in several lines in Python. A way to do it in JavaScript would be using several sentences and joining them with a `+` operator (I know, maybe it's not the most efficient way to do it, but I'm not really concerned about performance in this stage, just code readability). Example: var long_string = 'some text not important. just garbage to' + 'illustrate my example';I tried doing something similar in Python, but it didn't work, so I used `\\` to split the long string. However, I'm not sure if this is the only/best/pythonicest way of doing it. It looks awkward. Actual code: query = 'SELECT action.descr as "action", '\\  'role.id as role_id,'\\  'role.descr as role'\\  'FROM '\\  'public.role_action_def,'\\  'public.role,'\\  'public.record_def, '\\  'public.action'\\  'WHERE role.id = role_action_def.role_id AND'\\  'record_def.id = role_action_def.def_id AND'\\  'action.id = role_action_def.action_id AND'\\  'role_action_def.account_id = ' + account_id + ' AND'\\  'record_def.account_id=' + account_id + ' AND'\\  'def_id=' + def_id

1 Expert Answer

By:

Eddie B. answered • 03/20/19

Tutor
5 (3)

Purdue University student studying computer engineering

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.