[Tutor] or

alan.gauld@bt.com alan.gauld@bt.com
Wed, 26 Jun 2002 11:01:01 +0100


> >>>ffac.xlpol =u'NAB02658508'
> >>>if ffac.xlpol[0] == u's' or u'S':
> ... 	print"yes"
> ...
> yes
> 
> This is clearly wrong. 

No, its only apoparently wrong. It is in fact cprrect.

Python seeeds your test like:

if ffac.xlpol[0] == (u's' or u'S'):

and ('s' or 'S') is always true.

ffac.xlpol[0] is 'N' which in boolean terms is also 
true so far as Python is concerned.

thus tru == true so it prints yes!

What you need to do is break the test out like so:

if (ffac.xlpol[0] == u's') or (ffac.xlpol[0] == u'S'):
  print 'yes'

> If I remove the or and the last u'S' it works. 

Because now you are comparing letters with letters not 
letters with booleans.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld