[Tutor] Fwd: Defining "bit" type

Vicent vginer at gmail.com
Sat Jan 24 16:36:23 CET 2009


Sorry, I answered only to Eugene...



---------- Forwarded message ----------
From: Vicent <vginer at gmail.com>
Date: Sat, Jan 24, 2009 at 15:42
Subject: Re: [Tutor] Defining "bit" type
To: Eugene Perederey <eugene.perederey at gmail.com>



On Sat, Jan 24, 2009 at 15:31, Eugene Perederey
<eugene.perederey at gmail.com>wrote:

> Hi,
> type 'bool' takes only True and False. Is it what you want?
>
>

Well, it would be similar, but...

This is OK:

 >>> a = True
>>> type(a)
<type 'bool'>
>>> a == 1
True
>>> not a
False
>>> (not a) == 0
True
>>> a*0.5
0.5
>>> a*a
1
>>> type(a)
<type 'bool'>


But this is not nice:

>>> type(a)
<type 'bool'>
>>> a
True
>>> a = 0
>>> type(a)
<type 'int'>


I mean, being "a" a boolean variable, it works as if it was a number, but
every time I want to update the value of "a", I must put "False" for 0 and
"True" for 1, or it will change into an integer variable.

So, maybe I can adapt the definition of "bool" type, I don't know... Anyway,
I want to manage 0's and 1's, not "Falses" and "Trues".

--
Vicent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090124/f9cfb842/attachment.htm>


More information about the Tutor mailing list