1

I looked at similar questions but I didn't find this topic anywhere.

I want to know what does the tuple (1,) mean in Python?

8
  • 4
    wiki.python.org/moin/TupleSyntax Commented May 19, 2016 at 15:05
  • 1
    I'm not sure what you're asking here... it's just a tuple with one element, the integer 1. Commented May 19, 2016 at 15:05
  • @ajcr MAN! You have the answer??? Commented May 19, 2016 at 15:07
  • 2
    Related, but not really duplicate: stackoverflow.com/q/37313471/1639625 Commented May 19, 2016 at 15:08
  • @tobias_k Actually that was the question that forced me to ask this. Commented May 19, 2016 at 15:10

1 Answer 1

8

From https://wiki.python.org/moin/TupleSyntax

One Element Tuples

One-element tuples look like:

1,

The essential element here is the trailing comma. As for any expression, parentheses are optional, so you may also write one-element tuples like

(1,)

but it is the comma, not the parentheses, that define the tuple.

Sign up to request clarification or add additional context in comments.

4 Comments

Well, Multiple Element Tuples says the comma is also needed there, even though 1, 2, 3 successfully coerces to (1, 2, 3).
No the page clearly says that for multiple element tuples the trailing comma is optional.
but the trailing comma is completely optional. and but again, it is the commas, not the parentheses, that define the tuple. seem contradictory to me, tho.
@ΈρικΚωνσταντόπουλος The page says that for multiple element tuples The essential elements are the commas **between** each element of the tuple, so that should answer your question. The only place where trailing comma is essential is the single element case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.