Create a tuple with single item 23


The program is written in Python and it declares two variables t and tup. The first variable t is assigned the value 23. However, this value is not wrapped inside a tuple. In Python, a single value without a comma is not considered to be a tuple. The second variable tup is assigned the value (23,). This value is wrapped inside a tuple, with a comma at the end indicating that it is a tuple. The program then uses the print function to display the values of t and tup followed by the type of each value using the type function.

Source Code

t= (23)
print(t)
print(type(t))
tup = (23,)
print(tup)
print(type(tup))

Output

23
<class 'int'>
(23,)
<class 'tuple'>


Example Programs