DEV Community

Discussion on: Daily Challenge #276 - Unwanted Dollar Signs

Collapse
 
rafaacioly profile image
Rafael Acioly • Edited

You could also use the method strip

return float(string.strip("$"))

strip doc:

S.strip([chars]) -> str

Return a copy of the string S with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.

Thread Thread
 
imjoseangel profile image
Jose Angel Munoz • Edited

This doesn't work with string = "-$ 0.1" isn't it? I'd rather prefer the replace way :P