我有一大块文字。它有换行符,但由于换行符仍然很长,所以换行符会换行。由于所有其他脚本函数的所有行都缩进了一个空格,所以我希望能够匹配它。我知道,如果我只打印一行,我可以插入一个空格,如果我想在符合一行的换行符后缩进,我可以在它后面插入一个空格\n
。缩进控制台中的新行
如何让文本块中的每一行缩进? e.g:
text = """This is a block of text. It keeps going on and on and on. It has some line breaks \n but mostly just keeps going on without breaks. The lines are sometimes too long, so they wrap to the next line, but they don't indent. I need to fix this"""
,将打印为:
>>> print(text)
This is a block of text. It keeps going on
and on and on. It has some line breaks
but mostly just keeps going on without
breaks. The lines are sometimes too long,
so they wrap to the next line, but they
don't indent. I need to fix this
我无法导入连接或上层 – user6896502
@NateHailfire,您运行的是哪个版本的python? – blackpen