Why do I have to enclose the following code in brackets? Why is there a difference between square and round brackets?
>>> a= [1,2,3]
>>> (str(x) for x in a)
<generator object <genexpr> at 0x10ade8af0>
>>> [str(x) for x in a]
['1', '2', '3']
Why do I have to enclose the following code in brackets? Why is there a difference between square and round brackets?
>>> a= [1,2,3]
>>> (str(x) for x in a)
<generator object <genexpr> at 0x10ade8af0>
>>> [str(x) for x in a]
['1', '2', '3']
(str(x) for x in a)
is a generator expression
[str(x) for x in a]
is a list comprehension.