Computer Science
Which one of the following is correct to insert a single element in a tuple?
- T = 4
- T = (4)
- T = (4, )
- T = [4, ]
Python Tuples
1 Like
Answer
T = (4, )
Reason — In Python, to create a tuple with a single element, we need to include a trailing comma after the element. This tells Python that we are defining a tuple rather than just using parentheses for grouping. Thus, T = (4, ) creates a tuple with one element.
Answered By
1 Like
Related Questions
Which function is used to return a value for the given key?
- len()
- get()
- keys()
- None of these
Which function is used to remove all items from a particular dictionary?
- clear()
- pop()
- delete()
- rem()
Which of the following functions will return key-value pairs of the dictionary?
- key()
- values()
- items()
- get()
Which of the following will delete key-value pair for key = "Red" from a dictionary D1 ?
- delete D1("Red")
- del.D1("Red")
- del D1["Red"]
- del D1