Login or Sign up

In Python, do tuples have methods that lists don't have? Yes, __getnewargs__.

Posted by: skyl on Nov. 27, 2009

In [1]: t = tuple()

In [2]: l = list()

In [3]: for i in dir(t):
   ...:     if i not in dir(l):
   ...:         print "hey!", i, "is an attribute of the tuple but not of the list"
   ...:
   ...:
hey! __getnewargs__ is an attribute of the tuple but not of the list

In [4]: t.__getnewargs__.__doc__

In [5]: t.__getnewargs__()
Out[5]: ((),)

In [6]: t = (1,2,3)

In [7]: t.__getnewargs__()
Out[7]: ((1, 2, 3),)

Comments on This Post:

Please Login (or Sign Up) to leave a comment