Puzzling difference between lists and tuples

Avi Gross avigross at verizon.net
Sun Sep 20 18:59:15 EDT 2020


There is a simple and obvious way to make sure you have a tuple by invoking the keyword/function in making it:

>>> a=('first')
>>> type(a)
<class 'str'>

>>> a=("first",)
>>> type(a)
<class 'tuple'>

>>> a=tuple("first")
>>> type(a)
<class 'tuple'>

That seems more explicit than adding a trailing comma. It also is a simple way to make an empty tuple but is there any penalty for using the function tuple()?


-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net at python.org> On Behalf Of "???"
Sent: Saturday, September 19, 2020 11:39 PM
To: python-list at python.org
Subject: Re: Puzzling difference between lists and tuples

William Pearson <william.pearson at gmail.com> writes:

> ...
> for n in ('first'):
>     print n
>
>
> ... but "f","i","r","s","t" in the second.

#+BEGIN_SRC: python
for n in ('first',):
    print n
#+BEGIN_SRC

Then, that will print 'first'. And please use Python3...

Sincerely, Byung-Hee

-- 
^고맙습니다 _救濟蒼生_ 감사합니다_^))//
-- 
https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list