Get the App
SLTechnology News&Howtos  ›  Development  › 

How python uses multiline strings for ​

Shulou Source: shulou.com Published: 2022-06-01 06:20:34 10月03日 Update

This article is about how python uses multiline strings. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Use multiline strings

The basic approach is to use backslashes derived from the C language.

MultiStr = "select * from multi_row\ where row_id < 5" print (multiStr) # select * from multi_row where row_id < 5

Another technique is to use three quotation marks.

MultiStr = "select * from multi_row where row_id < 5"print (multiStr) # select * from multi_row # where row_id < 5"

The common problem with the above approach is the lack of proper indentation. If we try to indent, it inserts spaces in the string.

So the ultimate solution is to split the string into multiple lines and enclose the entire string in parentheses.

MultiStr= ("select * from multi_row"where row_id < 5"order by age") print (multiStr) # select * from multi_row where row_id < 5 order by age Thank you for reading! This is the end of this article on "how to use multi-line strings in python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Characters strings multilines contents methods more articles good practical appropriate quotes techniques parentheses articles slashes solutions see knowledge spaces solutions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Tech Info Microsoft OPPO Reno Docker