0% found this document useful (0 votes)
17 views4 pages

Tuple Methods&functions

good revision

Uploaded by

RIZWAN N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Tuple Methods&functions

good revision

Uploaded by

RIZWAN N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ZION AND ALWIN GROUP OF SCHOOLS

TUPLE METHODS AND FUNCTIONS


RETURNS
S.NO. FUNCTION /METHOD DESCRIPTION EXAMPLE
VALUE /NOT

returns length of the tuple ie) T=(967,"Python","tuple",[4,5])


number of elements in the tuple print(len(T)) print(len(T[3]))
1 len() yes

It returns the maximum element T1=("count","index","pop",'append')


from the tuple. All the tuple T2=(798,456,345,899)
elements must be of same type. print(max(T1))
2 max() yes T2=max(T2)
print(T2)

It returns the minimum element T1=("count","index","pop",'append')


from the tuple. All the tuple T2=(798,456,345,899)
print(min(T1))
3 min() elements must be of same type. yes T2=min(T2)
print(T2)

returns the indexof first matched T=('tuple','it','returns','tupl')


data item from the tuple. If the print(T.index('tuple'))
passed data item is not present in print(T.index("It"))
4 index() yes
the tuple it raises ValueError

returns count of dataitems T=('a','b','e','i','o','u','h','b')


present in the tuple. Returns zero print(T.count('b'),T.count('e'),sep="##")
5 count() yes print(T.count('z'))
if the item is not found.
RETURNS
S.NO. FUNCTION /METHOD DESCRIPTION EXAMPLE
VALUE /NOT
returns tuple from passed argument, s="method"
which should be sequence type t=('it','can','form','tuple')
(string,list,tuple,dictionary). If d={"roll":10,'name':'dict',1:'one'}
argument is not passed it creates print(tuple(s))
6 tuple() empty tuple. yes print(tuple(t))
print(tuple(d))

It sorts the elements of the tuple in T1=("count","index","pop",'append')


ascending order. This is not done in print(sorted(T1))
T2=sorted(T1,reverse=True)
place. It takes the tuple elements print(T1)
sort them and return as list. To sort print(T2)
the elements in descending order
7 sorted() the argument to be passed is yes
reverse=True as second argument.

It returns the sum of all the data L2=(798,456,345,899,9.8)


items in the list. All the data items L2=sum(L2)
8 sum() should be number type only yes print(L2)
HOOLS
UNCTIONS
OUTPUT

4
2
OUTPUT

2507.8

You might also like