KnowledgeBoat Logo

Computer Science

The syntax for a tuple with a single item is simply the element enclosed in a pair of matching parentheses as shown below :
t = ("a")
Is the above statement true? Why? Why not ?

Python Tuples

7 Likes

Answer

The statement is false. Single item tuple is always represented by adding a comma after the item. If it is not added then python will consider it as a string.
For example:
t1 = ("a",)
print(type(t1)) ⇒ tuple
t = ("a")
print(type(t)) ⇒ string

Answered By

5 Likes


Related Questions