Would this work for your situation?

>>> s = '12abcd405'
>>> result = ''.join([i for i in s if not i.isdigit()])
>>> result
'abcd'

This makes use of a list comprehension, and what is happening here is similar to this structure:

no_digits = []
# Iterate through the string, adding non-numbers to the no_digits list
for i in s:
    if not i.isdigit():
        no_digits.append(i)

# Now join all elements of the list with '', 
# which puts all of the characters together.
result = ''.join(no_digits)

As @AshwiniChaudhary and @KirkStrauser point out, you actually do not need to use the brackets in the one-liner, making the piece inside the parentheses a generator expression (more efficient than a list comprehension). Even if this doesn't fit the requirements for your assignment, it is something you should read about eventually :) :

>>> s = '12abcd405'
>>> result = ''.join(i for i in s if not i.isdigit())
>>> result
'abcd'
Answer from RocketDonkey on Stack Overflow
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python string remove numbers
Python String Remove Numbers - Spark By {Examples}
May 21, 2024 - How to remove numbers from the string in Python? You can remove numeric digits/numbers from a given string in Python using many ways, for example, by
Discussions

Remove all numbers in a list below a value
Don't remove items from a list you iterate over unless you do it in reverse order. Better to create a new list with the items you want to retain. More on reddit.com
๐ŸŒ r/learnpython
22
3
November 21, 2021
remove numbers string python - Stack Overflow
For my assignment, I have to create a function that returns a new string that is the same as the given string, but with digits removed. Example: remove digits(โ€™abc123โ€™) would return the string โ€™ab... More on stackoverflow.com
๐ŸŒ stackoverflow.com
October 7, 2016
string - Remove a digit from a number(integer) in python - Stack Overflow
For all indices, i am required to remove that place's Digit. An integer a, converting it to String, i.e. S. And there after iterate through the length of string, for i in range(len(S)): new =... More on stackoverflow.com
๐ŸŒ stackoverflow.com
October 28, 2017
How to remove a single number from input number in python - Stack Overflow
Here are few example input & outputs to understand the question example 1 input = 555 output should be = 55 example 2 input = 5455 output should be = 545 example 3 input = 6555 output More on stackoverflow.com
๐ŸŒ stackoverflow.com
February 15, 2022
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-ways-to-remove-numeric-digits-from-given-string
Python | Ways to remove numeric digits from given string - GeeksforGeeks
December 30, 2024 - import re s = "geeks123" result = re.sub(r'\d+', '', s) # Remove all digits from the string print(result) ... With this approach we iterate through each character in the string and check if itโ€™s an alphabet letter. isalpha() method returns True if the character is a letter and False if it is not. ... s = "geeks123" result = "" for char in s: if char.isalpha(): # Check if the character is not a number result += char # Add it to result if it's a letter print(result)
๐ŸŒ
CodeFatherTech
codefather.tech โ€บ home โ€บ blog โ€บ 4 ways to remove numbers from string in python
4 Ways to Remove Numbers From String in Python - CodeFatherTech
December 8, 2024 - To remove numbers from a string in Python you can use different techniques. The first option is to use a for loop that goes through every character in the string and creates a new string made of characters that are not numbers. You can achieve the same result using the string join() method ...
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ remove numbers from string python
How to Remove Numbers From String in Python | Delft Stack
February 2, 2024 - The below example code demonstrates how to use the string.join() method to remove the numbers from the string in Python.
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to remove numbers from a string in python
How to remove numbers from a string in Python | Replit
April 13, 2026 - Python offers several powerful methods to handle this operation with efficiency and precision. Here, you'll explore several techniques to remove numbers. You'll get practical tips, see real-world applications, and receive debugging advice to help you select the right approach for your use case. ... text = "Hello123World456" result = "" for char in text: if not char.isdigit(): result += char print(result)
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to Remove/Strip Numbers from a String in Python TUTORIAL (Common Python Interview Question) - YouTube
Python tutorial on how to remove numbers/integers/digits from a string.This is a common python interview question.Solution:'.join([i for i in x if not i.isdi...
Published ย  August 4, 2019
Find elsewhere
Top answer
1 of 4
2

UPDATE: It seems to be counterintuitive, but string-based solution is much faster then int-based. Here're my code and results in seconds for 103-, 226-digit and 472-digit numbers. I decided not to test 102139-digit number on my laptop :)

import timeit, math

digits = [100, 200, 500, 1_000, 2_000, 5_000, 10_000, 50_000, 100_000]

def print_str(n):
  s = str(n)
  for i in range(len(s)):
    #print(i)
    n2 = int(s[:i] + s[i+1:])


def print_int(a):
  p = 1
  while p <= a:
        n2 = a//p//10*p + a%p
        p *= 10

if __name__ == '__main__':
  number = 1
  for i in digits:
    n = 17**math.ceil(math.log(10**i, 17))
    str_ = timeit.timeit('print_str(n)', setup='from __main__ import print_str, n', number=number)
    int_ = timeit.timeit('print_int(n)', setup='from __main__ import print_int, n', number=number)
    print("{:8d}\t{:15.6f}\t{:15.6f}".format(len(str(n)), str_/number*1000, int_/number*1000))

Results (in milliseconds for particular number length):

$ time python3 main.py
     101           0.169280        0.185082
     201           0.502591        0.537000
     501           3.917680        3.195815
    1001          13.768999       22.781801
    2001         114.404890      120.546628
    5001        1066.541904     1625.172070
   10002        8033.144731     8802.031382
   50001      937385.167088  1045865.986814
  100002     7800950.456252  8189620.010314

First column - number of digits, second one - time in milliseconds for the str-based solution, and third - for the int-based.

But how is it possible?

It could be understood if we remember how endless integer numbers are constructed in Python. Under the hood there's an array of 15- or 30-bit integers which being joined produces the result number. So when you divide this number you have to walk through the whole array and modify every every digit. Also take in account complexity - sometimes you have to add or subtract from more significant digit, that complicates process.

When you use strings, you only copy bytes from one place to another. It's extremely fast procedure made with internal cpu instruction.

But what if we do not need conversion to int? For example, we want to print a number, so having it in a string form is better? How will it enfaster process?

Here're results - also in ms for different length

 $ time python3 main.py
     101           0.051510        0.124668
     201           0.091741        0.442547
     501           0.357862        2.562110
    1001           0.787016       15.229156
    2001           2.545076      111.917518
    5001           4.993472     1334.944235

UPD: Bencharks of updated versions:

$ time python3 main2.py

digits        str1        str2        int1        int2
   101       0.047       0.101       0.110       0.073
   201       0.091       0.315       0.380       0.145
   501       0.338       2.049       2.540       0.778
  1001       1.342      16.878      16.032       1.621
  2001       1.626      85.277      97.809       5.553
  5001       4.903    1039.889    1326.481      32.490
 10002      15.987    7856.753    9512.209     129.280
 20001      72.205   60363.860   68219.334     487.088

real    2m29.403s
user    2m27.902s
sys 0m0.577s
2 of 4
2

Another answer producing integers, much faster at that than my other answer and the OP's string solution:

>>> a = 12345

>>> digits = [0] + list(map(int, str(a)))
>>> p = 10**(len(digits) - 2)
>>> for x, y in zip(digits, digits[1:]):
        a += (x - y) * p
        p //= 10
        print(a)

2345
1345
1245
1235
1234

This goes from 2345 to 1345 by replacing the 2 with the 1, which it does by subtracting 2โ‹…1000 and adding 1โ‹…1000. Or in short, by adding (1-2)โ‹…1000. Then it goes from 1345 to 1245 by adding (2-3)โ‹…100. And so on.

Benchmark results, using a modified version of Eugene's program:

digits        str1        str2        int1        int2
   101       0.085       0.255       0.376       0.157
   201       0.161       0.943       1.569       0.389
   501       0.514       9.180       9.932       0.983
  1001       0.699      30.544      39.796       2.218
  2001       1.402     203.429     291.006       8.435
  5001       4.852    2691.292    3983.420      50.616
 10002      16.080   21139.318   29114.274     197.343
 20001      54.884  167641.593  222848.841     789.182

str1 is the time for the OP's string solution, producing strings.

str2 is the time for the OP's string solution, turning the strings into ints.
int1 is my other solution producing ints.
int2 is my new solution producing ints.

No surprise that the OP's string solution is the fastest overall. Its runtime complexity is quadratic in the number of digits. Which is the total output size, so that's optimal. My new solution is quadratic as well, but doing calculations is of course more work than pure copying.

For producing ints, my new solution is by far the fastest. My old one and the OP's have cubic runtime for that (with the OP's apparently being around 1.4 times as fast as my old one).

The benchmark program (modified version of Eugene's):

import timeit, math

digits = [100, 200, 500, 1_000, 2_000, 5_000, 10_000, 20_000]

def print_str_1(n):
  s = str(n)
  for i in range(len(s)):
    #print(i)
    n2 = s[:i] + s[i+1:]

def print_str_2(n):
  s = str(n)
  for i in range(len(s)):
    #print(i)
    n2 = int(s[:i] + s[i+1:])

def print_int_1(a):
  p = 1
  while p <= a:
        n2 = a//p//10*p + a%p
        p *= 10

def print_int_2(a):
    digits = [0] + list(map(int, str(a)))
    p = 10**(len(digits) - 2)
    for x, y in zip(digits, digits[1:]):
        a += (x - y) * p
        p //= 10
        #print(a)

if __name__ == '__main__':
  print(("{:>6}" + 4 * "{:>12}").format('digits', 'str1', 'str2', 'int1', 'int2'))
  number = 1
  for i in digits:
    n = 17**math.ceil(math.log(10**i, 17))
    str1 = timeit.timeit('print_str_1(n)', setup='from __main__ import print_str_1, n', number=number)
    str2 = timeit.timeit('print_str_2(n)', setup='from __main__ import print_str_2, n', number=number)
    int1 = timeit.timeit('print_int_1(n)', setup='from __main__ import print_int_1, n', number=number)
    int2 = timeit.timeit('print_int_2(n)', setup='from __main__ import print_int_2, n', number=number)
    print(("{:6d}" + 4 * "{:12.3f}").format(len(str(n)), *(x/number*1000 for x in (str1, str2, int1, int2))))
๐ŸŒ
AlgoCademy
algocademy.com โ€บ link
Remove K Digits in Python | AlgoCademy
Input: num = "10200", k = 1 Output: "200" Explanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes. ... Input: num = "10", k = 2 Output: "0" Explanation: Remove all the digits from the number ...
๐ŸŒ
Python Guides
pythonguides.com โ€บ remove-numbers-from-strings-in-python
How To Remove Numbers From Strings In Python?
March 19, 2025 - This pattern matches a specific format: three digits enclosed in parentheses, followed by an optional space, and then three digits, a hyphen, and four more digits. By replacing this pattern with an empty string, we remove the phone number from the string. Read Difference Between Functions and Methods in Python
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ list โ€บ remove
Python List remove()
# create a list prime_numbers = ... [2, 3, 5, 7, 11] The syntax of the remove() method is: list.remove(element) The remove() method takes a single element as an argument and removes it from the list....
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-38695.html
Remove numbers from a list
November 12, 2022 - I've been working a problem in another forum and ran across something I don't understand. Giving a list of numbers as input and then removing the numbers that are less than or equal to a boundry, can'
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_list_remove.asp
Python List remove() Method
The remove() method removes the first occurrence of the element with the specified value. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-remove-all-digits-from-a-list-of-strings
Python | Remove all digits from a list of strings - GeeksforGeeks
December 26, 2024 - This kind of application can come in many domains. Let's discuss certain ways to solve this problem. Method #1 : Using replace() + enumerate() + loop This is ยท 8 min read Python - Remove String from String List
๐ŸŒ
DaniWeb
daniweb.com โ€บ programming โ€บ software-development โ€บ threads โ€บ 225396 โ€บ remove-digits-from-iteger
python - Remove Digits from iteger | DaniWeb
def remove_digit_math(n, k): import math sign = -1 if n < 0 else 1 n = abs(n) d = int(math.log10(n)) + 1 if n else 1 if not (0 <= k < d): raise ValueError("k out of range") p = 10 ** (d - k - 1) left = n // (p * 10) right = n % p return sign * (left * p + right) # Fast path for "remove first digit from a 5-digit x": # new = x % 10000 # total = x + new ... leegeorg07, the idea to use indexing would work on a string, not an int. Converting to str before slicing is the right fix. Handle edge cases: negative numbers, k bounds, and the possibility that removing the only digit should yield 0. Both functions above cover these. Sorry guys...this is probably really trivial but i'm new to Python.