Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么我必须将以下代码括在括号中?为什么方括号和圆括号有区别?
>>> 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)是一个生成器表达式
(str(x) for x in a)
[str(x) for x in a]是一个列表理解。
[str(x) for x in a]