If you can't modify that string literal (for example, it's defined outside of your code), use inspect.cleandoc
or equivalent:
In [2]: import inspect
In [3]: s = inspect.cleandoc("""There is a bear here
...: The bear has a bunch of honey
...: The fat bear is in front of another door
...: How are you going to move the bear?
...: """)
In [4]: print(s)
There is a bear here
The bear has a bunch of honey
The fat bear is in front of another door
How are you going to move the bear?
If you can modify it, it's much easier to remove leading spaces manually:
def bear_room():
print("""There is a bear here
The bear has a bunch of honey
The fat bear is in front of another door
How are you going to move the bear?
""")
or use implicit string literal concatenation:
def bear_room():
print('There is a bear here\n'
'The bear has a bunch of honey\n'
'The fat bear is in front of another door\n'
'How are you going to move the bear?\n')
This option will produce expected results if you end strings with newline characters (\n
).