[Tutor] results: why different?

ali rmangaliag at slu.edu.ph
Thu Jan 15 22:36:32 EST 2004


thanks people... very clear...



----- Original Message ----- 
From: Daniel Ehrenberg <littledanehren at yahoo.com>
To: pytutor <tutor at python.org>
Sent: Thursday, January 15, 2004 10:03 PM
Subject: Re: [Tutor] results: why different?


> ali wrote:
> > 
> > why are the results of these codes different?
> > 
> > ###### 1 ######
> > 
> > if True==[1,2,3]:
> >     print "test"
> > 
> > ###### 2 ######
> > 
> > if [1,2,3]:
> >     print "test"
> > 
> > thanks...
> > 
> > ali
> 
> Think of the if keyword like it's converting its
> arguments into a boolean and *then* testing to see if
> they equal True. == doesn't do this. Obviously, [1, 2,
> 3] is not the same thing as True, but converted to a
> boolean, [1, 2, 3] is true. Here are some examples to
> show this more clearly:
> 
> >>> bool([1, 2, 3])
> True
> >>> [1, 2, 3] == True
> False
> >>> bool([1, 2, 3]) == True
> True
> >>> if [1, 2, 3]: print 'yes'
> yes
> >>> if bool([1, 2, 3]): print 'yes'
> yes
> >>> if [1, 2, 3] == True: print 'yes'
> >>> if bool([1, 2, 3]) == True: print 'yes'
> yes
> 
> Daniel Ehrenberg
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
> http://hotjobs.sweepstakes.yahoo.com/signingbonus
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list