Home > Mobile >  I want to print all alphabet letters in a string, but I do not get an output, not even an error
I want to print all alphabet letters in a string, but I do not get an output, not even an error

Time:12-29

I would like to print all alphabet letters in the string below, however, I do not get an output when I run the code. Not even an error. What am I doing wrong ?

x='a14b8c789d45e17'
for i in x:
    if i== '%s' %x:
       print(i)

#No output

CodePudding user response:

You're currently testing whether a single character equals the entire string. Instead, test each substring with the str.isalpha() method to test if they're letters or not:

x = 'a14b8c789d45e17'
for i in x:
    if i.isalpha():
       print(i)
  • Related