[Tutor] Fwd: Defining "bit" type

Kent Johnson kent37 at tds.net
Sat Jan 24 22:46:37 CET 2009


On Sat, Jan 24, 2009 at 10:36 AM, Vicent <vginer at gmail.com> wrote:

> 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".

You have an incorrect idea about how variables and assignment work in
Python. Type is associated with a value, not a name. You might want to
read this:
http://personalpages.tds.net/~kent37/kk/00012.html

and this classic:
http://effbot.org/zone/python-objects.htm

Kent


More information about the Tutor mailing list