How do I print a multiline string variable to the console without the indent?
At the moment I tried this without success:
# Grid.
grid = """rnbqkbnr
pppppppp
********
********
********
PPPPPPPP
RNBQKBNR"""
# Show grid.
print(grid)
The output is the following:
rnbqkbnr
pppppppp
********
********
********
PPPPPPPP
RNBQKBNR
This is the output where I am looking for:
rnbqkbnr
pppppppp
********
********
********
PPPPPPPP
RNBQKBNR
Use textwrap.dedent(text)
.
>>> from textwrap import dedent
>>> dedent("""\
rnbqkbnr
pppppppp
********
********
********
PPPPPPPP
RNBQKBNR""")
'rnbqkbnr\npppppppp\n********\n********\n********\nPPPPPPPP\nRNBQKBNR'
>>> print(_)
rnbqkbnr
pppppppp
********
********
********
PPPPPPPP
RNBQKBNR
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With