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

Gillou nospam at bigfoot.com
Wed Aug 8 13:57:54 EDT 2001


Bug...
You forgot the "y" in the vowels ;-)

"xauau" <xauau at yahoo.com.au> a écrit dans le message news:
87snf2mnpv.fsf at xeno.localhost...
> Lee <lee.r2d2 at ntlworld.com> writes:
>
> > Hi there, I wonder if someone could possibly tell me what is wrong with
> > the following statement. I'm extremely embarrased to ask but here
> > goes...
> >
> > >>>  if (fname[1] == 'a'|'e'|'i'|'o'|'u'):
> >     vowel='true'
> >
> > Traceback (innermost last):
> >   File "<pyshell#46>", line 1, in ?
> >     if (fname[1] == 'a'|'e'|'i'|'o'|'u'):
> > TypeError: bad operand type(s) for |
>
> The | operator doesn't expect characters as its operands. (Even if it
> did, I doubt think you'd get the results you expected, but to explain
> why is a long(er) story) ;-)
>
> If you really need a more detailed answer, ask away. If you just want
> to make it work, try this:
>
> if fname[1] in 'aeiou':
> vowel = 'true'
>
>
>
>





More information about the Python-list mailing list