Flat 10% & upto 50% off + 10% Cashback + Free additional Courses. Hurry up
×
UPTO
50%
OFF!
• Live Instructor-led Classes
• Expert Education
• 24*7 Support
• Flexible Schedule

Tuple is an ordered collection of arbitrary objects. They work exactly like lists, except that tuples can’t be changed in place because they are immutable and parentheses are used rather than square brackets. If parenthesis is not specified then it by default treated as tuple. Tuples share most of their properties with lists. They are:

• Accessed by offset
• Of the category immutable sequence
• Fixed length, heterogeneous, arbitrarily nestable
• Arrays of object references

e.g.

```T1 =(1, 2, 3,"intellipaat")

print T1
```

Output

(1, 2, 3,’intellipaat’)

Tuples are accesses same like as list.

Operations on List

On list following operation are performed:

• Concatenate Tuple

+ Operator is used to concatenate two tuples.

```T1 = (1, 2, 3, 4)

T2 = (5, 6, 7, 8)

print T1+T2
```

Output

(1, 2, 3, 4, 5, 6, 7, 8)

• Replicate Tuples

Operator * is used to repeat a tuple by specific number of time.

```T1=(1,2)

print T1*2
```

Output

(1,2, 1, 2)

• Sub Tuple

It is used to obtain a sub Tuple which is done by specifying the index.

```T1 = (1, 2, 3, 4)

print T1[0:3]
```

Output

(1, 2, 3)

• Update List

Updation is not possible in tuple because tuples are immutable objects.

• Deletion

In tuple you cannot delete individual value in tuple. Using del you can delete entire tuple at a time.

```T1 = (1, 2, 3, 4)

del T1

print L1
```

Output

Traceback (most recent call last):

File “C:/Python27/t.py”, line 3, in

print T1

NameError: name ‘T1’ is not defined

Functions in Tuple

 Function Description min(tuple) Returns the minimum value from a tuple max(tuple) Returns the maximum value from the tuple len(tuple) Gives the length of a tuple tuple(sequence) Converts the sequence into tuple cmp(tuple1,tuple2) Compares the two tuple
Previous Next

#### Download Interview Questions asked by top MNCs in 2018?

Learn SQL in 16 hrs from experts

### "0 Responses on Python Tuples"

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

## Sales Offer

• To avail this offer, enroll before 11th December 2018.
• This offer cannot be combined with any other offer.
• This offer is valid on selected courses only.
• Cashback will be accumulated in Intellipaat e-wallet
• Please use coupon codes mentioned below to avail the offer