Python Exercise: Create a tuple with different data types
2. Create a Tuple with Different Data Types
Write a Python program to create a tuple with different data types.
Sample Solution:
Python Code:
# Create a tuple containing elements of different data types
tuplex = ("tuple", False, 3.2, 1)
# Print the contents of the 'tuplex' tuple
print(tuplex)
Sample Output:
('tuple', False, 3.2, 1)
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to construct a tuple that contains an integer, a float, a string, and a complex number.
- Write a Python program to create a tuple with elements of at least four different data types and print each element’s type.
- Write a Python program to generate a tuple from user inputs where each input is automatically converted to its appropriate data type.
- Write a Python program to build a tuple that includes a nested tuple and a list, and then print the type of each element recursively.
Python Code Editor:
Previous: Write a Python program to create a tuple.
Next: Write a Python program to create a tuple with numbers and print one item.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics