Python tuple
is an immutable ordered collection of items:
>>> ohlc = (25.05, 25.81, 24.97, 25.10) >>> type(ohlc) <class 'tuple'>
Most characteristic are the same for tuples
and lists
. Both can contain zero, one, or more items, which can be duplicate and can be of different types.
You can find any item from a tuple using its index (start from zero).
>>> ohlc[2] 24.97
Main difference from list
is that a tuple
is immutable. It can't be changed once created.
>>> ohlc = (25.05, 25.81, 24.97, 25.10) >>> ohlc[1] = 25.90 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'tuple' object does not support item assignment