How to pad a string with zeros in Python

1 Answer

0 votes
s = 'python'

print(s.rjust(9,"0"))

print(s.ljust(12,"0"))

s = s.rjust(10,"0")
s = s.ljust(16,"0")

print(s)




'''
run:

000python
python000000
0000python000000

'''

 



answered Feb 3, 2022 by avibootz

Related questions

1 answer 171 views
1 answer 202 views
1 answer 155 views
1 answer 128 views
128 views asked May 29, 2024 by avibootz
...