I want to delete the number using replace String (.replace('0', ").Is there a way to specify a number as a whole other than to enter all numbers from 0 to 9 in this way?
python
munja = 'fda0sf1g3h54l6o8u7g9......'
for i in range(10):
munja = munja.replace('%s'%i,'')
print munja
# Execution result: 'fdasfghloug...'
Or if you use a regular expression.
import re
munja = 'fda0sf1g3h54l6o8u7g9......'
num = re.compile('[\d]+')
print num.subn('', munja, 8)
# Execution result: ('fdasfghloug....', 8) #where 8 means 8 digits replaced by a space.
You can change your mind and sort out the ones that aren't numbers.
In [1]: munja = 'fda0sf1g3h54l6o8u7g9'
In [2]: "".join(c for c in munja if not c.isdigit())
Out[2]: 'fdasfghloug'
© 2024 OneMinuteCode. All rights reserved.