版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaotao_1/article/details/80945393
python3:加入end= ' '
参数。
python2:以逗号结尾。 两个例子如下:
>>> a = [1, 2, 3, 4]
# python3编译环境
>>> for i in a:
... print(i, end=' ')
1 2 3 4
# python2编译环境
>>> for i in a:
... print i,
1 2 3 4
ps:很多编程笔试题,输出数据都要求以空格隔开。