The Python tuples are sequences that are used to store a tuple of values of any type. • Tuples are immutable. • Tuple is a type of sequence like string and list but it differs from them in way that lists are mutable but strings and tuples are immutable Creating and Accessing Tuples Tuples are depicted through parenthesis. () Empty tuple (1,2,3) Tuple of integers (2,3.5,6,7.5) Tuple of integer and float (‘ x’,’y’,’z ’) Tuples of characters Creating Tuples 1. Empty Tuple >>> t=tuple() >>> t () 2. Single Element >>> t=(1) >>> t 1 >>> t=3 , # to construct a tuple with one element just add comma >>> t (3,) 3. Long Tuples >>> t1=(11,22,33,44,55,66,77,88) >>> t1 (11, 22, 33, 44, 55, 66, 77, 88) >>> print (t1) (11, 22, 33, 44, 55, 66, 77, 88) 4. Nested Tuples : t=(11,22,(33,44),55) >>> t (11, 22, (33, 44), 55) Creating Tuple...
Thanks for sharing all the information with us all.
ReplyDeletePython Online Training
Post it in the future in articlepython class
ReplyDelete