ACCEPTED: PEP 285

Tim Peters tim.one at comcast.net
Thu Apr 4 21:13:25 EST 2002


[James Logajan]
> ...
> If a bool is to be treated as an int sometimes and sometimes not,

bool is a subclass of int that overrides only the constructor, __str__ and
__repr__ methods.

> I don't recall seeing anything about whether it will be treated as
> an int as a dictionary key.

Provided you don't convert it to string via str() or repr() first before
using it as a dict key, yes.

> If I do:
>
> x = ["is", "are"]
> y = {0: "", 1:"s"}
>
> for n in range(3):
>    print "There %s %d item%s." % (x[n <> 1], n, y[n <> 1])
>
> Will the behavior be backword compatible and equivalent or not? Simple
> question I assume; waiting for an answer.

C:\Code\python\PCbuild>python
Python 2.3a0 (#29, Apr  3 2002, 20:49:03) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x = ["is", "are"]
>>> y = {0: "", 1:"s"}
>>> for n in range(3):
...     print "There %s %d item%s." % (x[n <> 1], n, y[n <> 1])
...
There are 0 items.
There is 1 item.
There are 2 items.
>>>






More information about the Python-list mailing list