__getitem__, __getslice__ question for python 2.2
Just van Rossum
just at xs4all.nl
Wed May 15 03:38:28 EDT 2002
In article <mailman.1021446748.5956.python-list at python.org>,
Ken Seehof <kseehof at neuralintegrator.com> wrote:
> I don't see the problem. If x is 'a', x != int(x) evaluates to false,
> consistent with 'a' not being an integer.
>>> x = 'a'
>>> x != int(x)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): a
>>>
> If x is 2.0, the expression evaluates to true. People will argue
> about whether or not this is correct. It may or may not be correct,
> depending on why you want to constrain x to an integer. In many
> cases it is appropriate to consider 2.0 to be an integer. It depends
> on the context.
>>> range(5)[2.0]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: sequence index must be integer
>>>
Just
More information about the Python-list
mailing list