ID EN
Text Wrapping

dedent

Python 3.11

Remove any common leading whitespace from every line in text.

Syntax

PYTHON
textwrap.dedent(text)

Examples

Example 1
PYTHON
def test():
     end first line with \ to avoid the empty line!
    s = '''\
    hello
      world
    '''
    print(repr(s))           prints '    hello\n      world\n    '
    print(repr(dedent(s)))   prints 'hello\n  world\n'