Sunday, 25 August 2013

Why do I get [...] when I append a list to the same list in python?

Why do I get [...] when I append a list to the same list in python?

The following code was tried in a Python 2.7.1 interpreter.
>>> a = [1, 2, 3]
>>> a.append(a)
>>> a
[1, 2, 3, [...]]
>>> a == a[-1]
True
>>> print a[-1]
[1, 2, 3, [...]]
Can anyone please explain what python is trying to do here?

No comments:

Post a Comment