Aug-25-2019, 12:19 AM
,
outside of data structure like eg list it will always make a tuple.>>> 1, 2 (1, 2) >>> 'hello', 'world' ('hello', 'world')So
for x in 1,2,3:
is just the same as for x in (1,2,3):
In a list is
,
parsed as separator,then 1, 2, 3 is three separate element and not a tuple.For it to be a tuple or list inside a list comprehension then have to make it so
() []
.>>> [x for x in (1,2,3)] [1, 2, 3] >>> [x for x in [1,2,3]] [1, 2, 3]