Tuple Python

 #  A BUILT IN DATA TYPE IMMUTABLE SEQUENCE OF VALUES

# tup=(10,20,30,40,20)
# print(type(tup))

# access element
# print(tup[1])

# if tuple size is 1 , then we write with comma like- (1,)
# tup=(1,)
# print(tup)

# slicing
# print(tup[1:3])

# unpacking a tuple
# tup=("ved","ram","sam")
# n1,n2,n3=tup
# print(n1,n2,n3)

# METHODS->
# index() -  return index of first occurence
# print(tup.index(20))

# count() -  count total occurence of element
# print(tup.count(20))

# reverse tuple-

# rev_tup=tuple(reversed(tup))
# print(rev_tup)

# list=[]
# for i in reversed(tup):
#     list.append(i)
# rev_tup=tuple(list)
# print(rev_tup)

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.