[PYTHON] Quickly list multiple lines of text in your code

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.']

reference

"Triple quotes" in https://docs.python.jp/3/tutorial/introduction.html#strings

Recommended Posts

Quickly list multiple lines of text in your code
Copy of multiple List
List of Python code used in big data analysis
List of nodes in diagrams
Decrypt one line of code in Python lambda, map, list
Extract multiple list duplicates in Python
Delete multiple elements in python list
Count Source lines of code (SLOC)
Get a list of packages installed in your current environment with python
Handling of character code of file in IronPython
[Linux] List of Linux commands used in practice
Summary of built-in methods in Python list
[Bash] Redirection of multiple lines to multiple files
Try text mining your diary in Python
Get the EDINET code list in Python
An era when text classification by BERT is possible with 3 lines of code
List of main probability distributions used in machine learning and statistics and code in python
[Python] Sort the list of pathlib.Path in natural sort
Argument implementation (with code) in your own language
Make a copy of the list in Python
Search by the value of the instance in the list
List of Python code to move and remember
Sort tuple list in Python by specifying the ascending / descending order of multiple keys