bing
Flat 10% & upto 50% off + Free additional Courses. Hurry up!

Python Tuples

 

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

"0 Responses on Python Tuples"

Training in Cities

Bangalore, Hyderabad, Chennai, Delhi, Kolkata, UK, London, Chicago, San Francisco, Dallas, Washington, New York, Orlando, Boston

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

top

Sales Offer

  • To avail this offer, enroll before 10th December 2016.
  • This offer cannot be combined with any other offer.
  • This offer is valid on selected courses only.
  • Please use coupon codes mentioned below to avail the offer
offer-june

Sign Up or Login to view the Free Python Tuples.