Write multiple lines of text in your code This is the code when you want to convert to a list of 1 line and 1 element.
textlist.py
textlist = """\
Quickly
Multi-line text
I want to make a list.
Text here
It is an image to paste.
""".splitlines()
Verification
print(textlist)
['Quickly', 'Multi-line text', 'I want to make a list.', 'Text here', 'It is an image to paste.']
If there is no \
at the end of the first line, the line feed code will come first, and as a result, an empty string will come to the first element.
textlist.py
textlist = """
Quickly
Multi-line text
I want to make a list.
Text here
It is an image to paste.
""".splitlines()
Verification
print(textlist)
['', 'Quickly', 'Multi-line text', 'I want to make a list.', 'Text here', 'It is an image to paste.']
"Triple quotes" in https://docs.python.jp/3/tutorial/introduction.html#strings
Recommended Posts