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

xauau xauau at yahoo.com.au
Wed Aug 8 14:05:32 EDT 2001


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