Python 无法使用join打印列表

Python 无法使用join打印列表,python,python-2.7,python-3.x,Python,Python 2.7,Python 3.x,下面的代码抛出一个错误 squares = map(lambda a: a*a, [1,2,3,4,5]) print "%d." %", ".join(squares) 我应该如何打印它?我希望结果是一样的 1,4,9,16,25.改变 print "%d." %", ".join(squares) 到 如果要在行尾追加,请使用: print '%s.'%", ".join(map(str, squares)) 或者简单地print“,”.join(map(str,squares))

下面的代码抛出一个错误

squares = map(lambda a: a*a, [1,2,3,4,5])  
print "%d." %", ".join(squares)
我应该如何打印它?我希望结果是一样的 1,4,9,16,25.

改变

print "%d." %", ".join(squares)

如果要在行尾追加
,请使用:

print '%s.'%", ".join(map(str, squares))
或者简单地
print“,”.join(map(str,squares))+”。

如果您使用的是python3,
print
将成为一个内置函数。打开列表并使用@Ashwini Chaudhary提到的
sep=','

print(*squares, sep=', ')
返回一个字符串,该字符串是
iterable(
squares

对于Python3:
print(*squares,sep=',')
应该这样做。@zhangxaochen:现在它说的是
TypeError:sequence item 0:expected string,int find
@mario23如果你想添加句点标记
,请查看我的更新。
print(*squares, sep=', ')