I have a string that will later be converted with int()
. It is three digits, anywhere from 0 to 3 of them might be 0's. How would I strip the 0s from the left side of the string?
Now I'm using string.lstrip('0')
but that strips all the 0s and makes the string empty, causing an error.
You can do it like this:
s = str(int(s))
Another alternative is:
s = s.lstrip('0') or '0'
You want str.lstrip()
for that. But maybe you should just pass the radix to int()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With