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: Make Python create a tuple with one element in a clean way
Type: enhancement Stage:
Components: Versions: Python 3.0, Python 2.4, Python 2.3, Python 2.2.3, Python 2.6, Python 2.2.2, Python 2.5, Python 2.2.1, Python 2.2, Python 2.1.2, Python 2.1.1, 3rd party
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, chester, georg.brandl, loewis
Priority: normal Keywords:

Created on 2008-05-11 13:16 by chester, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg66626 - (view) Author: Chester (chester) Date: 2008-05-11 13:16
To create a tuple with one element, you need to do this:

>>> my_tuple = (1,)    # Note the trailing comma after the value 1
>>> type(my_tuple)
<type 'tuple'>


But if you do this

>>> my_tuple = (1)
>>> type(my_tuple)
<type 'int'>

you don't get a tuple. I thought that just putting a value inside ( )
would make a tuple. Apparently that is not the case. I hate ugly code
so it would be clean if Python would convert anything put into ( ) to
be a tuple, even if just one value was put in (without having to use
that ugly looking comma with no value after it).
msg66627 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-05-11 13:18
But we need parentheses for grouping!
msg66634 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-11 14:18
That's an absolute no-starter. Not the parentheses make the tuple, the
commas do. The empty tuple is the exception, not the rule.
msg66645 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-05-11 16:50
Just in case the previous comments aren't clear: Would you rather see

py> (3+4)*5
35

or

py> (3+4)*5
(7, 7, 7, 7, 7)
msg66650 - (view) Author: Chester (chester) Date: 2008-05-11 18:51
Martin I see the point now. I appologize for not having the clear head
of seeing the possible damage that my feature request would make. I take
my request back.
History
Date User Action Args
2022-04-11 14:56:34adminsetgithub: 47066
2008-05-11 18:51:24chestersetmessages: + msg66650
2008-05-11 16:50:36loewissetnosy: + loewis
messages: + msg66645
2008-05-11 14:18:41georg.brandlsetstatus: open -> closed
resolution: rejected
messages: + msg66634
nosy: + georg.brandl
2008-05-11 13:18:11benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg66627
2008-05-11 13:16:16chestercreate