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 <[email protected]> On
Behalf Of "???"
Sent: Saturday, September 19, 2020 11:39 PM
To: [email protected]
Subject: Re: Puzzling difference between lists and tuples
William Pearson <[email protected]> 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
--
https://mail.python.org/mailman/listinfo/python-list