Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python print indentations

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')
like image 809
ragardner Avatar asked Dec 18 '22 08:12

ragardner


2 Answers

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')
like image 54
ragardner Avatar answered Dec 20 '22 21:12

ragardner


level = 3
print (" "*level, 'indented text')
like image 25
Mr.Pacman Avatar answered Dec 20 '22 21:12

Mr.Pacman