Why isn't it possible to strip the decimal point off of a float?
str(1.5).strip(".")
returns 1.5
Why doesn't it return 15
?
Has the decimal point an own symbol that is not equal with the full stop .
?
str.strip()
only removes characters at the beginning and end, not in the middle. It's mostly used for removing extraneous whitespace around a line of input (with no argument, it defaults to removing whitespace).
Use str.replace()
to replace a string anywhere:
str(1.5).replace('.', '')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.