Important Notice:

Tuples in Python

Tuples in Python

16 views 1 min read

Tuples

A tuple is an ordered, immutable collection.

t = (1, 2, 3, "hello")\npoint = (10, 20)Tuple vs ListFeatureListTupleMutableYesNoSyntax[ ]( )SpeedSlowerFasterTuple Operationst = (10, 20, 30, 20)\nt[0] # 10\nlen(t) # 4\nt.count(20) # 2\nt.index(30) # 2Packing & Unpackingt = (1, 2, 3) # packing\na, b, c = t # unpacking