tuple methods

Solutions on MaxInterview for tuple methods by the best coders in the world

showing results for - "tuple methods"
Soukaina
06 Apr 2018
1my_tuple = ('a','p','p','l','e',)
2
3# len() : get the number of elements in a tuple
4print(len(my_tuple))
5
6# count(x) : Return the number of items that is equal to x
7print(my_tuple.count('p'))
8
9# index(x) : Return index of first item that is equal to x
10print(my_tuple.index('l'))
11
12# repetition
13my_tuple = ('a', 'b') * 5
14print(my_tuple)
15
16# concatenation
17my_tuple = (1,2,3) + (4,5,6)
18print(my_tuple)
19
20# convert list to a tuple and vice versa
21my_list = ['a', 'b', 'c', 'd']
22list_to_tuple = tuple(my_list)
23print(list_to_tuple)
24
25tuple_to_list = list(list_to_tuple)
26print(tuple_to_list)
27
28# convert string to tuple
29string_to_tuple = tuple('Hello')
30print(string_to_tuple)
31
Agustina
08 Oct 2019
1count(x) : Returns the number of times 'x' occurs in a tuple
2index(x) : Searches the tuple for 'x' and returns the position of where it was first found
queries leading to this page
tuple in pythonpython tuple all methodshow to define a tuple pythonpython tuple operationspython tuple mehodwhat is tuple in pythontuple functions and methodstuple definition pythonwhats a tuple in pythontuple in python what isfunctions in tuple pythonpython tuple methodsfunctions on python tupleswhat is python tupletuple python functionbuilt in function in tuple pythontuple functions in pythonmethod tuple pythontuple method sin pythontuple function pythonpython all tuple use functionpython what is tupletuple methods pythonmethods of tuple in pythonpython tuple methods and functionslist and tuple methods in pythontuple python methodpython tuple tuple in pythonfunctions of tuple in pythontuple all methods in pythontuple methods in pythonwhat is tuple used in pythontuple python methodspython tupletuple function in pythonpython 3 tuples methodstuple functions in python 3tuples methods in pythonmethods for tuple ion pythontuple functions pythonpython tuple usesbuilt in tuple functions in pythonexplain tuple methods with exampleuse of tuple in pythonmethods of tuple object in pythontuple built in methods in pythonoperations on tuple in pythonpython functoion tupleswhy tuple is used in pythonmethods in tuplewhat is a tuple in pythontuple meaning in pythonpython tuple examplepython all tuple methodspython what is a tupletuple pythonmethods in python tupletuple for calling methodspython using tupleoperations with tuple pythonpython tuple methodpython tuple functions and methodstuple 28 29 pythonfunction tuple pythontuple 28 29 in pythontuple support methodspython tuple methodsdtuple syntax in pythonwhat is a tuple object in pythontuple example in pythontuple methodstuple methods python 3tuple methods