How to remove (strip) all digits from a string in Python

2 Answers

0 votes
s = "1234p345y435th345on56789"

result = ''.join([ch for ch in s if not ch.isdigit()])

print(result)


'''
run:
 
python

'''

 



answered Sep 4, 2018 by avibootz
edited Mar 18, 2024 by avibootz
0 votes
s = "1234p345y435th345on56789"

new_s = []
for ch in s:
    if not ch.isdigit():
        new_s.append(ch)

result = ''.join(new_s)

print(result)


'''
run:
 
python

'''

 



answered Sep 4, 2018 by avibootz
edited Mar 18, 2024 by avibootz

Related questions

3 answers 295 views
1 answer 198 views
6 answers 755 views
1 answer 135 views
2 answers 271 views
...