Argument of the bool function
Benjamin Kaplan
benjamin.kaplan at case.edu
Fri Apr 8 12:41:50 EDT 2011
On Fri, Apr 8, 2011 at 12:26 PM, candide <candide at free.invalid> 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
>>>>
>
>
> but _expression_ :
>
> x=42
>
>
> has no value.
>
That's because bool(x=5) isn't doing what you think.
>>> bool(y=5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'y' is an invalid keyword argument for this function
bool(x=5) is just passing the value 5 as the argument "x" to the function.
"value" means just what you'd think- any constant or any value that's
been assigned to.
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list