+ 1
How to print the digits present in a string?(ex:- abc123 gives 123)
3 Réponses
+ 4
If you like it, you can also do it in a comprehension:
a = 'a1b2c3d4'
print(*[i for i in a if i.isdigit()], sep='')
# output: 1234
# or in a for loop:
for i in a:
if i.isdigit():
print(i, end='')
+ 3
One line:
print("".join([i for i in "abc123" if i.isdigit()]))