Possible Duplicate:
python str.strip strange behavior
I have following piece of code:
st = '55000.0'
st = st.strip('.0')
print st
When i execute, it print only 55 but i expect it to print 55000. I thought that the dot in strip causing this as we usually escape it in Regular Expression so i also tried st = st.strip('\.0') but still is giving same results. Any ideas why it is not just striping .0 and why all zeros striped??
You've misunderstood strip() - it removes any of the specified characters from both ends; there is no regex support here.
You're asking it to strip both . and 0 off both ends, so it does - and gets left with 55.
See the official String class docs for details.
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