How to right align text (right-justified) in Python

3 Answers

0 votes
print('{:>35}'.format('python right aligned'))


 
'''
run:
 
               python right aligned
  
'''

 



answered Jul 29, 2019 by avibootz
0 votes
string = 'python'
width = 20

print(string.rjust(width))


 
'''
run:
 
              python
  
'''

 



answered Jul 29, 2019 by avibootz
0 votes
string = '$100'
width = 20

print(string.rjust(width, '*'))



 
'''
run:
 
****************$100
  
'''

 



answered Jul 29, 2019 by avibootz

Related questions

...