👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
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
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from Pythonc way to create a long multi-line string, check other code Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Pythonc way to create a long multi-line string
- Deutsch Pythonc way to create a long multi-line string
- Français Pythonc way to create a long multi-line string
- Español Pythonc way to create a long multi-line string
- Türk Pythonc way to create a long multi-line string
- Русский Pythonc way to create a long multi-line string
- Português Pythonc way to create a long multi-line string
- Polski Pythonc way to create a long multi-line string
- Nederlandse Pythonc way to create a long multi-line string
- 中文 Pythonc way to create a long multi-line string
- 한국어 Pythonc way to create a long multi-line string
- 日本語 Pythonc way to create a long multi-line string
- हिन्दी Pythonc way to create a long multi-line string
Munchen | 2023-03-29
I was preparing for my coding interview, thanks for clarifying this - Pythonc way to create a long multi-line string in Python is not the simplest one. Will use it in my bachelor thesis
Massachussetts | 2023-03-29
Thanks for explaining! I was stuck with Pythonc way to create a long multi-line string for some hours, finally got it done 🤗. I am just not quite sure it is the best method
Vigrinia | 2023-03-29
Thanks for explaining! I was stuck with Pythonc way to create a long multi-line string for some hours, finally got it done 🤗. Will get back tomorrow with feedback