-3

Is there a custom way of padding lines of text in python, I am using the escape characters "\t", but I wonder if there is an alternative. for example

print('My Name is:')
print('Rambo')
print('Mambo')

Output:

.My Name is:
.....Rambo
..Mambo
espktro
  • 127
  • 1
  • 1
  • 7

2 Answers2

1

Try using:

print('{:>15}'.format('My Name is:'))

Refer for examples: PyFormat

atg
  • 173
  • 1
  • 16
  • Seems to work, but does not work, the first print works, but the next prints are awful/ – espktro Jun 28 '17 at 05:55
  • change the variable '15' according to your need.. don't expect this as an exact solution Its just an example ;) – atg Jun 28 '17 at 06:06
0

Write a simple function for yourself.

def p(a,b):
 print(" "*a + b)

p(1,"while")

This should return:" while"

Nick
  • 49
  • 3