python2和python3输出数据用空格隔开,不换行。

版权声明:本文为博主原创文章,未经博主允许不得转载。 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:很多编程笔试题,输出数据都要求以空格隔开。

猜你喜欢

转载自blog.csdn.net/xiaotao_1/article/details/80945393