Answer
tpl1 = ('A',) - Tuple
tpl1 = ('A') - String
t = tpl[::-1] - Sorts tuple
('A', 'B', 'C', 'D') - tuple of strings
[(1, 2), (2, 3), (4, 5)] - list of tuples
tpl = tuple(range(2, 5)) - (2, 3, 4)
([1, 2], [3, 4], [5, 6]) - tuple of lists
t = tuple('Ajooba') - tuple of length 6
Explanation:
tpl1 = ('A',) - This creates a tuple named tpl1 containing a single element 'A'. Note the comma after 'A', which is essential for creating a tuple with a single element.
tpl1 = ('A') - This actually creates a string, not a tuple. To create a tuple with a single element, you need to include a comma: tpl1 = ('A',).
t = tpl[::-1] - This reverses the order of elements in the tuple tpl. The [::-1] slicing notation is used to reverse the sequence.
('A', 'B', 'C', 'D') - This is a tuple of strings with four elements: 'A', 'B', 'C', and 'D'.
[(1, 2), (2, 3), (4, 5)] - This is a list of tuples, where each tuple contains two integers.
tpl = tuple(range(2, 5)) - This creates a tuple named tpl with elements generated using range(2, 5), resulting in the tuple (2, 3, 4).
([1, 2], [3, 4], [5, 6]) - This is a tuple of lists, where each list contains two integers.
t = tuple('Ajooba') - This creates a tuple named t from the characters of the string 'Ajooba'. The resulting tuple has six elements, one for each character.
0 Comments:
Post a Comment