Tuple and list

Thetuple() and list() functions take any kind of sequence. Here's what happens if you passtuple () e tuple:

>>> tup = (1,2,3) >>> id(tup), id(tuple(tup)) (201160, 201160)

As you can see, the id of tup and Che id owtUg tuple returned from tuple () aro the sawe. We can demonstrate this with the ideklily operator, which returns as a true statement that tup is tuple(tup).

If you pess e list to tuple (), you get a new tuple.

>>> id(lst), id(tuple(lst)) (332828, 321564)

Notice thet, every time you cell list(ls) , you get e sew copy of ls.

Was this article helpful?

0 0

Post a comment