Is An Element of a Sequence an Object?
Marko Rauhamaa
marko at pacujo.net
Sun Jun 4 03:03:03 EDT 2017
Jon Forrest <nobozo at gmail.com>:
> On 6/3/2017 5:23 PM, Steve D'Aprano wrote:
>> On Sun, 4 Jun 2017 05:10 am, Jon Forrest wrote:
>
>> We can fix the book's statement by changing it to:
>>
>> A sequence is an ordered collection of *elements* ...
>
> That's exactly what I was thinking, but then there'd have to
> be a clear definition of "element".
Instead of getting into metaphysical explanations, one should define the
concepts operationally.
A *sequence* is an object s that supports (most of) these operations:
x in s
x not in s
s + t
s * n
n * s
s[i]
s[i:j]
s[i:j:k]
len(s)
min(s)
max(s)
s.index(x[, i[, j]])
s.count(x)
<URL: https://docs.python.org/3/library/stdtypes.html#common-sequenc
e-operations>
As sequence is *mutable* if it additionally supports (most of) these
operations:
x[i] = x
x[i:j] = t
del s[i:j]
s[i:j:k] = t
del s[i:j:k]
s.append(x)
s.clear()
s.copy()
s.extend(t)
s += t
s *= t
s.insert(i, x)
s.pop([i])
s.remove(x)
s.reverse()
<URL: https://docs.python.org/3/library/stdtypes.html#mutable-sequenc
e-types>
Marko
More information about the Python-list
mailing list