To pad the string on the right with spaces or any other character you can use the str.ljust(width[, fillchar]) method. The fillchar arg is used to specify the character to fill. For example:
Example
To pad the string on the left with spaces or any other character you can use the str.ljust(width[, fillchar]) method. The fillchar arg is used to specify the character to fill. For example:
print('Mona Lisa'.ljust(12)) print('Mona Lisa'.ljust(12,'$'))
Output
Mona Lisa Mona Lisa$$$