programplug Logo

Python Tuple

Tuple also work as a data structure,A tuple is a sequence of immutable objects.Tuple cannot be changed,it store different type of data.
The objects are enclosed within parenthesis and separated by comma.

item1 = (1,2,3,4,5);
item2 = ('a','b','c','d');
item3 = (1,'a',2.30,"abc");
item4 = 'a','b','c','d';
item = (); #empty tuple

Tuple example

item1 = (1,2,3,'a');
item2 = (1, 2, 3, 4, 5, 6, 7 );
print "item1[3];
print "item2[2:6];

(3, 4, 5, 6, 7 )

Tuple Delete Elements

Tuple does not support single element deleting.Only entire tuple can remove,by using the del statement.

item = (1,2,3,'a');
print item;
del item;
print "After deleting Item : ";
print item;

After deleting Item : NameError: name 'item' is not defined

Tuple Updating Element

Due to the immutable object tuple element can not update.Only by using existing tuples to create new tuples.

item1 = (1,2,3,4);
item2 = (1,2,3,4);
item3 = item1+item2;
print item3;


Our Services

Developing Cheapest Websites
Offer Digital Marketing
Provide College Projects
Attractive Website Developing
Summer Training,Industrial Training

Contact Us

Dehradun Uttarakhand India

Other Link

About Us

Contact Us


Privacy Policy