2

I discovered a humorous situation when playing around in Python 2.7. It seems that when I append a list onto itself, it seems to infinitely append itself onto the list. Here is the example that I used:

>>> x = ['a','b','c']
>>> x.append(x)
>>> x
['a', 'b', 'c', [...]]
>>> x[3]
['a', 'b', 'c', [...]]
>>> x[3][3][3]
['a', 'b', 'c', [...]]
>>> x[3][2]
'c'

Why wouldn't it just output as:

>>> x = ['a','b','c']
>>> x.append(x)
>>> x
['a', 'b', 'c', ['a','b','c']]

I'm just curious as to why this happens. I can't seem to find anything that adequately explains why this is. Thank you all very much!

Robert Link
  • 367
  • 2
  • 9

0 Answers0