KnowledgeBoat Logo
|

Computer Science

Which one of the following is correct to insert a single element in a tuple?

  1. T = 4
  2. T = (4)
  3. T = (4, )
  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