lists v. tuples

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Mar 17 14:22:48 CET 2008


On Mon, 17 Mar 2008 05:28:19 -0700, castironpi wrote:

> a tuple is a data
> structure such which cannot contain a refrence to itself.



>>> a = []  # a list
>>> b = (a, None)  # a tuple
>>> a.append(b)
>>> print b
([([...], None)], None)
>>> b[0][0] is b
True


So, yes tuples can contain a reference to themselves, but only indirectly.



> Can a single expression refer to itself ever?

You can't refer to an object until it exists, so no.




-- 
Steven



More information about the Python-list mailing list