Tuples in Python

tuples are similar to lists ,tuples are sequnces too,but the diffrences is tuples are immutable,they cant be modified once they are created

tuples can be easliy created by using parentheses( ),and elmets can be seperated by commas ( , )

zone = ("zone1", "zone2", "zone3")

converting to tuples

we can use tuple constructer function converting normal strings and list to tuples

conv = tuple([10,20,30,40])

##tuple indexing

tuples indexing are same as the list indexing,we can start our index number with 0 from the beggining of the elemnet and we can acess last element by sing -1 as the index reverse number

example = ("cat","dog","ox","goat")
example[0] #'cat'

##deleting a tuple

you can delete tuple easily by using del key word ,example is given below

del example

slicing tuples

we can slice tuples just like lists,all we need to do is to provide the starting index and the ending index of the tuple

animals = ("cat","dog","ox","goat","monkey","buffalo","lion","tiger")
('goat', 'monkey')
('cat', 'dog', 'ox', 'goat')

##max and min in tuples

x = (324,2,5,35,3,46,4,56,54,7,547,56,76,243)
min(x) #2
x = (324,2,5,35,3,46,4,56,54,7,547,56,76,243)
max(x) #547
Last updated on by vishal devxo