mercredi 4 janvier 2017

Why does my if statement not work? (Python) [duplicate]

This question already has an answer here:

I wanted to write program in python that cleans up words from symbols. However after running this code:

def cleanup(st):
    f = 0
    g = 0
    str(st)
    for _ in st:
        f += 1
    lst = [''] * f
    for c in st:
        if c == "a" or "b" or "c" or "d" or "e" or "f" or "g" or "h" or "i" or "j" or "k" or "l" or "m" or "n" or "o"\
                or "p" or "q" or "r" or "s" or "t" or "u" or "v" or "w" or "x" or "y" or "z":
            lst[g] = c
            g += 1
    print("lst: ", lst)


cleanup("car.']0av]0987a]n") 

I allways get

lst:  ['c', 'a', 'r', '.', "'", ']', '0', 'a', 'v', ']', '0', '9', '8', '7', 'a', ']', 'n']

so everything passes. My if statement seems not to work. Can anyone explain me why this doesn't work and why if statement is always evaluated true? (I am working on Windows 10, Python 3.6)

Aucun commentaire:

Enregistrer un commentaire