How do you create a tuple with a single element?

How do you create a tuple with a single element?

To make a tuple with just one item in Python, you have to put a comma after the item, even if there's only one item. Here's how you do it:

single_element_tuple = (element,)

For example:

single_element_tuple = (42,)
print(single_element_tuple)  # Output: (42,)

Without the comma, Python will think the parentheses are for showing precedence in an expression, not for making a single-element tuple. So, adding the comma shows the difference between a single-element tuple and an expression in parentheses.