# Python Tuples

## Python Tuples

June 14, 2018
1 likes
454 times viewed #### Description

This article will guide you about the use of tuples in python. It will explain various functionalities and builtin functions associated with it.

## Tuple

### Basic Tuple Operations

Concatenation

``````>>> (1, 2, 3) + (4, 5, 6)
(1, 2, 3, 4, 5, 6)
``````

Repetition

``````>>> ("kode", )*4
('kode', 'kode', 'kode', 'kode')
``````

Membership

``````>>> 3 in (1, 2, 3, 4, 5)
True
``````

Indexing

``````>>> T=('C++', 'Java', 'Python')
>>> T
'Python'
>>> T[-2]
'Java'
``````

Slicing

``````>>> T = (1, 2, 4, 7, 3, 9)
>>> T[2:4]
(4, 7)
>>> T[2:]
(4, 7, 3, 9)
>>> T[:2]
(1, 2)
>>> T[:]
(1, 2, 4, 7, 3, 9)
``````

### Tuple Builtin Functions

len(tuple)

Gives the total length of the tuple.

``````>>> tuple1, tuple2 = (123, 'xyz', 'zara'), (456, 'abc')
>>> len(tuple1)
3
>>> len(tuple2)
2
``````

max(tuple)

Returns item from the tuple with max value.

``````>>> tuple1, tuple2 = ('maths', 'che', 'phy', 'bio'), (456, 700, 200)
>>> max(tuple1)
'phy'
>>> max(tuple2)
700
``````

min(tuple)

Returns item from the tuple with min value

``````>>> tuple1, tuple2 = ('maths', 'che', 'phy', 'bio'), (456, 700, 200)
>>> min(tuple1)
'bio'
>>> min(tuple2)
200
``````

tuple(s)

Converts s to a tuple.

``````>>> list1= ['maths', 'che', 'phy', 'bio']
>>> tuple(list1)
('maths', 'che', 'phy', 'bio')
>>> tuple("astik")
('a', 's', 't', 'i', 'k')
``````