[Tutor] Defining "bit" type

Kent Johnson kent37 at tds.net
Sun Jan 25 14:03:54 CET 2009

On Sun, Jan 25, 2009 at 5:13 AM, Vicent <vginer at gmail.com> wrote:

> I think I hadn't get that "0" is always integer, but now I get it. If I want
> to make it boolean (bit-like), it should be referred as "bool(0)".   [It is
> like that, isn't it????]

Yes, though bool(0) is actually creating a new bool object with the
same true/false value as the integer 0. It's not the same as a cast in
C that just looks at the same value in a new way. You can also do
things like
In [1]: bool("hello")
Out[1]: True

In [2]: bool("")
Out[2]: False

In [3]: bool([1,2,3])
Out[3]: True

In [4]: bool([])
Out[4]: False

In each case it is creating a new bool value.


More information about the Tutor mailing list