Skip to main content

Posts

Featured

Tuple

A tuple is a sequence of immutable Python objects. A tuple contains heterogeneous datatype. Basic Syntax of declaring tuple is t1 = (23 , 'tuple' )          from parentheses we know it is tuple    Accessing Values in Tuples: To access values in tuple, use the square brackets for slicing along with the index or indices to obtain value available at that index. For example tup1 = ( 'physics' , 'chemistry' , 1997 , 2000 ); tup2 = ( 1 , 2 , 3 , 4 , 5 , 6 , 7 ); print "tup1[0]: " , tup1 [ 0 ] print "tup2[1:5]: " , tup2 [ 1 : 5 ]       When the above code is executed, it produces the following result     tup1[0]: physics tup2[1:5]: [2, 3, 4, 5] Updating Tuples Tuples are immutable which means you cannot update or change the values of tuple elements. You are able to take portions of existing tuples to create new tuples as the following example demonstrates  tup1 = ( 12 , 34.56 ); tup2 = ( '

Latest posts

Python basics

Spyder (Python 3.5)

Comparing Python with Other Languages

Download Python