> For the complete documentation index, see [llms.txt](https://george-jen.gitbook.io/data-science-and-apache-spark/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://george-jen.gitbook.io/data-science-and-apache-spark/python-tuple.md).

# Tuple

### Tuple

immutable, tuple can not be modified. Modify a tuple variable result in a new tuple.

Tuple usually is in parentheses (), for example: (1,2,3,4,5) or (‘a’,’b’,’c’) or (1,2,3,’a’,’b’,’10’)

However, parentheses is not indicative to tuple, comma is. Tuple must have comma.

Like list, tuple is a sequence, iterable

t=(‘a’,’b’,’c’)

t\[0]=“a”

t\[1]=“b”

t\[2]=“c”

It is zero based indexing, index starts from zero

Tuple can be iterated through:

```
for i in t:
    print(i)
```

Convert to Tuple, use function tuple()

For example:

```
tuple("12345")
('1', '2', '3', '4', '5')

tuple([1,2,3,4,5])
(1, 2, 3, 4, 5)

tuple(12345)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-cc97692a48d4> in <module>
----> 1 tuple(12345)

TypeError: 'int' object is not iterable
```

Tuple is an object, meaning it has methods and attributes that can be invoked

To see all methods, type

help(\<tuple variable>)

In Jupyter notebook, to see list of methods or attributes

Press shift key after enter \<tuple variable>.

![](/files/-M1fbmwUIHqdOpMvJvvL)
