[Tutor] trouble with function-- trying to check differences btwn 2 strings
wesley chun
wescpy at gmail.com
Tue Mar 6 23:28:48 CET 2007
> >>> x=('i' in 'i')
> >>> x
> True
> >>> y='i'
> >>> x==y
> False
you're right when you talk about "casting" altho that's not what
python does. it merely performs an object value comparison when you
use '=='. for example, change your code above to:
>>> True == 'i' # because this is what you're really doing with x==y
False
so the reason why you get a false is that those 2 values *are*
different from each other, even if their boolean truthfulness may be
the same:
>>> bool(True) == bool('i')
True
how's *that* for casting? :-)
just remember that the interpreter compares *values* and not boolean
truthfulness, and you'll be ok. if you really want the latter, then
use bool().
hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com
wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
More information about the Tutor
mailing list