# Python Tuples

> Learn how to use tuples in Python, the immutable and ordered data structure created with parentheses, including indexing, slicing, len(), sorted() and more.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-12-19 | Topics: [Python](https://flaviocopes.com/tags/python/) | Canonical: https://flaviocopes.com/python-tuples/

Tuples are another fundamental [Python](https://flaviocopes.com/python-introduction/) data structure.

They allow you to create immutable groups of objects. This means that once a tuple is created, it can't be modified. You can't add or remove items.

They are created in a way similar to lists, but using parentheses instead of square brackets:

```python
names = ("Roger", "Syd")
```

A tuple is ordered, like a list, so you can get its values referencing an index value:

```python
names[0] # "Roger"
names[1] # "Syd"
```

You can also use the `index()` method:

```python
names.index('Roger') # 0
names.index('Syd')   # 1
```

As with strings and lists, using a negative index will start searching from the end:

```python
names[-1] # True
```

You can count the items in a tuple with the `len()` function:

```python
len(names) # 2
```

You can check if an item is contained into a tuple with the `in` operator:

```python
print("Roger" in names) # True
```

You can also extract a part of a tuple, using slices:

```python
names[0:2] # ('Roger', 'Syd')
names[1:] # ('Syd',)
```

Get the number of items in a tuple using the `len()` global function, the same we used to get the length of a string:

```python
len(names) #2
```

You can create a sorted version of a tuple using the `sorted()` global function:

```python
sorted(names)
```

You can create a new tuple from existing tuples using the `+` operator:

```python
newTuple = names + ("Vanille", "Tina")
```
