Write a Python program to create a tuple with numbers and print one item


The program is written in Python and performs the following steps:

  • A variable a is defined with the integer value 5.
  • The value of a is printed to the console.
  • The data type of a is printed to the console using the type() function.
  • The same variable a is redefined as a tuple with one item, the integer value 5. The trailing comma , is used to indicate that a is a tuple, even though it has only one item.
  • The value of a is printed to the console.
  • The data type of a is printed to the console using the type() function.

In Python, the trailing comma , is used to create tuples with a single item. In this case, the variable a is first defined as an integer 5, and then redefined as a tuple with one item 5. The print statement and type() function are used to display the value and data type of a after both definitions.

Source Code

a = 5
print(a)
print(type(a))
#create tuple of one item
a = 5,
print(a)
print(type(a))
 

Output

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

Example Programs