Python tuple Data Type

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

By remaining on this website or using its content, you confirm that you have read and agree with the Terms of Use Agreement.

We are not liable for any damages resulting from using this website. Any information may be inaccurate or incomplete. See full Limitation of Liability.

Content may include affiliate links, which means we may earn commission if you buy on the linked website. See full Affiliate and Referral Disclosure.

We use cookies and similar technology to improve user experience and analyze traffic. See full Cookie Policy.

See also Privacy Policy on how we collect and handle user data.

© 2024 PyTut