1#a tuple is basically the same thing as a
2#list, except that it can not be modified.
3tup = ('a','b','c')
1example = [1, 2, 3, 4]
2# Here is a list above! As we both know, lists can change in value
3# unlike toples, which are not using [] but () instead and cannot
4# change in value, because their values are static.
5
6# list() converts your tuple into a list.
7tupleexample = ('a', 'b', 'c')
8
9print(list(tupleexample))
10
11>> ['a', 'b', 'c']
12
13# tuple() does the same thing, but converts your list into a tuple instead.
14
15print(example)
16
17>> [1, 2, 3, 4]
18
19print(tuple(example))
20
21>> (1, 2, 3, 4)
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
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