Bu durumunuz için işe yarar mı?
>>> s = '12abcd405'
>>> result = ''.join([i for i in s if not i.isdigit()])
>>> result
'abcd'
Bu, bir liste anlayışından yararlanır ve burada olanlar şu yapıya benzer:
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)
@AshwiniChaudhary ve @KirkStrauser'ın da belirttiği gibi, aslında tek satırdaki parantezleri kullanmanıza gerek yok, bu da parantez içindeki parçayı bir üreteç ifadesi haline getiriyor (liste anlayışından daha verimli). Bu, ödevinizin gereksinimlerine uymasa bile, sonunda okumanız gereken bir şey :):
>>> s = '12abcd405'
>>> result = ''.join(i for i in s if not i.isdigit())
>>> result
'abcd'
re:result = re.sub(r'[0-9]+', '', s)