在Python 3.x中如何打印缩进的空格,我正在寻找的方法看起来像这样
level = 3
print ('% indent symbol' % * level, 'indented text')
应打印:
indented text
从下面重复回答:感谢@sudo_coffee的\ t
print ('\t' * level, 'indented text')
或者也许:
print ((' ' * 4) * level, 'indented text')
答案 0 :(得分:4)
print ('\t' * level, 'indented text')
或者也许:
print ((' ' * 4) * level, 'indented text')
答案 1 :(得分:1)
缩进,或输入"标签"空间量,使用转义序列\t
。
level = 3
print ('\t indented text')
答案 2 :(得分:1)
level = 3
print (" "*level, 'indented text')
答案 3 :(得分:0)
level = 3
indented_symbol = " "
print '{} Indented text'.format(indented_symbol*level)