Python Tuple With One Item


Create Tuple With One Item

To create a tuple with only one item, you have add a comma after the item, otherwise Python will not recognize the variable as a tuple.

Example

One item tuple, remember the commma:

thistuple = ("apple",)
print(type(thistuple))

#NOT a tuple
thistuple = ("apple")
print(type(thistuple))
Try it Yourself »


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.