This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tuple - single value with comma is assigned as type tuple
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: JelleZijlstra, acue, steven.daprano
Priority: normal Keywords:

Created on 2016-06-05 17:06 by acue, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg267434 - (view) Author: Arno-Can Uestuensoez (acue) Date: 2016-06-05 17:06
A single value terminated by a comma is assigned to be a tuple, even when missing parenthesis.

a=(1)  =>  a=1    OK/defined as
a=(1,) =>  a=(1,) OK
a=1,   =>  a=(1,) ???

Is the latter intended?

------------------
In [4]: a=1,

In [5]: print a
(1,)

In [6]: type(a)
Out[6]: tuple
-------------------
msg267436 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2016-06-05 17:09
Yes, this is intentional. It is documented in https://docs.python.org/3/reference/expressions.html#expression-lists: 

"The trailing comma is required only to create a single tuple"
msg267438 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2016-06-05 17:14
Yes, it is intended. Commas create tuples, not parentheses. (With the exception of the empty tuple.) The parens are just for grouping and precedence. `1,` is a tuple, regardless of whether you use parens around it or not.
History
Date User Action Args
2022-04-11 14:58:32adminsetgithub: 71421
2016-06-05 17:14:57steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg267438

resolution: not a bug
stage: resolved
2016-06-05 17:09:08JelleZijlstrasetnosy: + JelleZijlstra
messages: + msg267436
2016-06-05 17:06:46acuecreate