Python print indentations
12,864
Solution 1
sorry guys, think I found the answer, thanks to @sudo_coffee for \t
print ('\t' * level + 'indented text')
or maybe:
print ((' ' * 4) * level + 'indented text')
Solution 2
To indent, or enter a "tab" amount of space, use the escape sequence \t
.
level = 3
print ('\t indented text')
Solution 3
level = 3
print (" "*level, 'indented text')
![ragardner](https://i.stack.imgur.com/EBAoK.jpg?s=256&g=1)
Comments
-
ragardner about 2 years
In Python 3.x how do you print an indent of white space, the method I am looking for looked something like this
level = 3 print ('% indent symbol' % * level, 'indented text')
should print:
indented text
repeating answer from below: thanks to @sudo_coffee for \t
print ('\t' * level, 'indented text')
or maybe:
print ((' ' * 4) * level, 'indented text')