Argument of the bool function

Mel mwilson at the-wire.com
Fri Apr 8 12:42:22 EDT 2011


candide wrote:
> About the standard function bool(), Python's official documentation 
> tells us the following :
>> bool([x])
> Convert a value to a Boolean, using the standard truth testing procedure.
>> In this context, what exactly a "value" is referring to ?
>> For instance,
> >>> x=42
> >>> bool(x=5)
> True
> >>>

Cute. What's happening here is that `x=5` isn't really an expression. 
It's passing a value to the named parameter `x`, specified in the
definition of `bool`. Try it with something else:
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> bool(y=5)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: 'y' is an invalid keyword argument for this function
Mel.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /