ID EN
Text Wrapping

indent

Python 3.11

Add prefix to the beginning of selected lines in text.

Syntax

PYTHON
textwrap.indent(text, prefix, predicate=None)

Examples

Example 1
PYTHON
>>> s = 'hello\n\n \nworld'
>>> indent(s, '  ')
'  hello\n\n \n  world'
Example 2
PYTHON
>>> print(indent(s, '+ ', lambda line: True))
+ hello
+
+
+ world