5
Question Question 5
Which of the following will create a single element tuple ?
- (1,)
- (1)
- ( [1] )
- tuple([1])
(1,) and tuple([1])
Reason — (1,) To create a tuple with only one element, comma needs to be added after the element, otherwise Python will not recognize the variable as a tuple and will consider it as an integer.tuple([1]) tuple() function takes any iterable as an argument and hence when u pass a list it makes the list elements as its values.
Here, 1 is enclosed in square brackets which signifies list. When [1] is being passed as an argument in a tuple, it will generate a single element tuple with element is equal "1".