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

3 Answers

0 votes
print('{:<40}'.format('python left aligned'), "php")


 
'''
run:
 
python left aligned                      php
  
'''

 



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

print(string.ljust(width, '*'), '|')



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

 



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

print(string.ljust(width), '|')



 
'''
run:
 
python               |
  
'''

 



answered Jul 29, 2019 by avibootz

Related questions

3 answers 355 views
1 answer 148 views
148 views asked Jul 29, 2019 by avibootz
1 answer 167 views
1 answer 262 views
1 answer 144 views
...