Python: Replace integers by floats in string -


i'm looking way, replace every number inside string float number. i'd turn this: "3/1" this: "3.0/1.0" there way this?

you can use re.sub :

>>> s="3/1"  >>> import re >>> re.sub(r'(\d+)',r'\1.0',s) '3.0/1.0' >>> s="334/14"  >>> re.sub(r'(\d+)',r'\1.0',s) '334.0/14.0' 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -