October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk1 min

Python Tuple With One Element: Add the Comma

A one-element Python tuple needs a comma after its value: (value,). Without the comma, parentheses simply group the value.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create a Python tuple containing one value, put a comma after the value: one_item = (value,). The comma makes it a tuple; parentheses alone only group an expression.

Write a comma after the value

Use this form for a one-element tuple:

single = ('hello',)
print(single)  # ('hello',)

Python’s language reference requires a trailing comma when a tuple display has exactly one element. The comma-separated values define the tuple; parentheses are often used to make the tuple’s boundaries clear. See the Python language reference.

As an Amazon Associate I earn from qualifying purchases.

Why (value) is not a tuple

Parentheses by themselves group an expression. So ('hello') evaluates to the string 'hello', while ('hello',) evaluates to a tuple containing that string.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
not_a_tuple = ('hello')  # a string
one_item = ('hello',)    # a one-element tuple

Examples with different values

The same comma rule applies regardless of the value’s type:

number = (42,)
text = ('hello',)
flag = (True,)
none_value = (None,)

Other tuple forms

  • () creates an empty tuple.
  • (first, second) creates a tuple with two values. A final comma is optional when there is more than one element.
  • value, is also tuple syntax in a context that accepts a comma-separated expression list, though (value,) makes the intent more obvious.

PEP 8 likewise says that a trailing comma is mandatory for a one-element tuple: When to Use Trailing Commas.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.