October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober 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

Convert a String to a Tuple in Python

In Python, tuple(text) creates one tuple item per character. Split first with split() or split(delimiter) when you need words or separated fields.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use tuple(text) when you want each character in a string to become an item. To make a tuple of words or other fields, split the string first, then pass the result to tuple().

Convert each character into a tuple item

A string is iterable, so tuple() places its items—in this case, its characters—in order:

text = "abc"
result = tuple(text)

print(result)  # ('a', 'b', 'c')

This follows Python’s documented example: tuple('abc') produces ('a', 'b', 'c'). Use this form when individual characters, rather than words, should be the tuple’s elements.

Convert words or separated fields into a tuple

Call split() to divide a string into parts, then convert the resulting list to a tuple.

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

Split on whitespace to get words

text = "red green blue"
words = tuple(text.split())

print(words)  # ('red', 'green', 'blue')

With no separator argument, str.split() treats consecutive whitespace as a single boundary and omits empty items caused by whitespace at the beginning or end.

Split on a specific delimiter

text = "red,green,blue"
fields = tuple(text.split(","))

print(fields)  # ('red', 'green', 'blue')

Passing a separator makes the split literal. For example, tuple("1,,2".split(",")) returns ('1', '', '2'): consecutive commas create an empty field. An explicit separator on an empty string also preserves an empty field: tuple("".split(",")) returns ('',).

Choose the conversion that matches the intended items

Desired tuple items Expression Example result
Characters tuple(text) tuple("abc") → ('a', 'b', 'c')
Words separated by whitespace tuple(text.split()) tuple("red green".split()) → ('red', 'green')
Fields separated by a chosen delimiter tuple(text.split(delimiter)) tuple("red,green".split(",")) → ('red', 'green')
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Remember the comma for a one-item tuple

If splitting produces one item, tuple() still returns a tuple. When writing a tuple literal directly, the comma—not the parentheses—is what marks a single-item tuple: (value,) or value,. Python’s tuple syntax documentation explains this distinction.

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.

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

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.