Is An Element of a Sequence an Object?

Chris Angelico rosuav at gmail.com
Sun Jun 4 00:39:21 EDT 2017


On Sun, Jun 4, 2017 at 2:17 PM, Jon Forrest <nobozo at gmail.com> wrote:
> On 6/3/2017 4:58 PM, Chris Angelico wrote:
>
>> A sequence doesn't necessarily "contain" anything.
>
>
> Maybe not always, but doesn't
>
> "abc"
>
> contain three characters? Is 'contain' the right word?

That's a tricky thing to pin down. Since it's possible for a sequence
to contain itself, or to contain something which contains it,
"contain" is clearly not in any physically-equivalent sense. Does the
list [1, 2, 3] contain the float value 2.0? Not in any object-identity
sense, and not in the sense that you'll get 2.0 by iterating over it,
but yes, in the sense of __contains__. So this list "contains", in one
sense, objects that may not have existed previously. In the same way,
the string "abc" contains three characters, but it may not contain any
objects representing them.

In an abstract sense, the string DOES contain those characters. So
long as we don't discuss the concrete definitions of objects, yes,
we're fine.

ChrisA



More information about the Python-list mailing list