Python Quiz

Terry Reedy tjreedy at udel.edu
Thu Jul 17 14:23:50 EDT 2003


"Grant Edwards" <grante at visi.com> wrote in message
news:3f156c23$0$166$a1866201 at newsreader.visi.com...
> Yup. I found a lot of things in FORTRAN surprising.  Python is
> so much nicer in that respect.  Though I was recently surprised
> that the remove() method for lists uses "==" and not "is" to
> determine what to remove.  It's documented that it works that
> way. But, it wasn't what I excpected, and it took me a while to
> figure out that it was using my class's __cmp__ method rather
> than the object ID.

Given ints = [9, 99, 999, 9999] would it not surprise you even more if
ints.remove(99) worked and ints.remove(999) did not, or even worse, if
the behavior of ints.remove(99) depended on the implementation?
(Similar examples apply to strings, where the implementation of
interning and hence behavior based on identity *has* changed!)

Terry






More information about the Python-list mailing list