Planet Python

Python Morsels: Multiline strings

The article discusses how to represent multiple lines of text in Python using multi-line string syntax. It presents an example of a Python program called stopwatch.py that acts as a timer, counting upward one second at a time. The program uses a string with line breaks to display a usage statement when run with command-line arguments. The usage statement is represented as a single string with newline characters (\n) to separate the lines. This approach can be cumbersome for longer strings. An alternative is to use string concatenation to build up long strings. However, Python provides a more convenient way to create multi-line strings using triple quotes. Triple quotes allow you to create a string that spans multiple lines without needing newline characters. This makes the code more readable and easier to maintain. The article provides a link to a full tutorial on multi-line strings in Python.
favicon
pythonmorsels.com
pythonmorsels.com
Image for the article: Python Morsels: Multiline strings
Create attached notes ...