Is An Element of a Sequence an Object?

Thomas Jollans tjol at tjol.eu
Sun Jun 4 06:02:16 EDT 2017


On 04/06/17 09:52, Rustom Mody wrote:
> On Sunday, June 4, 2017 at 12:45:23 AM UTC+5:30, Jon Forrest wrote:
>> I'm learning about Python. A book I'm reading about it
>> says "... a string in Python is a sequence. A sequence is an ordered
>> collection of objects". This implies that each character in a string
>> is itself an object.
>>
>> This doesn't seem right to me, but since I'm just learning Python
>> I questioned the author about this. He gave an example the displays
>> the ids of string slices. These ids are all different, but I think
>> that's because the slicing operation creates objects.
>>
>> I'd like to suggest an explanation of what a sequence is
>> that doesn't use the word 'object' because an object has
>> a specific meaning in Python.
>>
>> Am I on the right track here?
> 
> Its a good sign that you are confused
> If you were not (feeling) confused, it would mean you are actually more so…
> Following is not exactly what you are disturbed by... Still closely related
> 
>>>> s="a string"
>>>> s[0]
> 'a'
>>>> s[0][0]
> 'a'
>>>> s[0][0][0][0][0]
> 'a'

Also:

>>> s[0] is s[0][0][0][0][0][0][0]
True
>>>



> 
> If you prefer jargon, elements of a string are not first class
> 




More information about the Python-list mailing list