if-else with '|' operator - beginner's question/problem

Skip Montanaro skip at pobox.com
Wed Aug 8 13:51:02 EDT 2001


    if (fname[1] == 'a'|'e'|'i'|'o'|'u'):
        vowel='true'

Try this instead:

    if fname[1] in "aeiou":
        vowel = "true"

or if you're not married to the vowel="true" bit:

    vowel = fname[1] in "aeiou"

seems somewhat cleaner to me.  It will have a value of 1 (true) or 0 (false)
depending on the value of the "in" expression.

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list