Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How can I eliminate numbers in a string in Python?
You can create an array to keep track of all non digit characters in a string. Then finally join this array using "".join method.
example
my_str = 'qwerty123asdf32' non_digits = [] for c in my_str: if not c.isdigit(): non_digits.append(c) result = ''.join(non_digits) print(result)
Output
This will give the output
qwertyasdf
example
You can also achieve this using a python list comprehension in a single line.
my_str = 'qwerty123asdf32' result = ''.join([c for c in my_str if not c.isdigit()]) print(result)
Output
This will give the output
qwertyasdf
Advertisements
