# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://george-jen.gitbook.io/data-science-and-apache-spark/python-tuple.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
