python print 按逗号或空格分隔的方法

yipeiwu_com4年前Python基础

1)按,分隔

a, b = 0, 1 
while b < 1000: 
 print(b, end=',') 
 a, b = b, a+b 
1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,

2)按空格分隔

a, b = 0, 1 
while b < 1000: 
 print(b, end=' ') 
 a, b = b, a+b 

1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 

3)print的用法

print(...)
 print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
 
 Prints the values to a stream, or to sys.stdout by default.
 Optional keyword arguments:
 file: a file-like object (stream); defaults to the current sys.stdout.
 sep: string inserted between values, default a space.
 end: string appended after the last value, default a newline.
 flush: whether to forcibly flush the stream.

以上这篇python print 按逗号或空格分隔的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

numpy ndarray 取出满足特定条件的某些行实例

在进行物体检测的ground truth boxes annotations包围框坐标数据整理时,需要实现这样的功能: numpy里面,对于N*4的数组,要实现对于每一行,如果第3列和第...

PyCharm的设置方法和第一个Python程序的建立

PyCharm的设置方法和第一个Python程序的建立

1.代码编辑 字体大小设置 进入 File—》Settings—》Editor—》Colors & Fonts—》Font中。 首先要点击“Save as”然后为这个设置命名,我这里填入...

python定时复制远程文件夹中所有文件

本文实例为大家分享了python定时复制远程文件夹中文件的具体代码,供大家参考,具体内容如下 import os, shutil, sys import threading impo...

Python的Django框架中settings文件的部署建议

django在一个项目的目录结构划分方面缺乏必要的规范,因此不同人的项目组织形式也千奇百怪,而且也很难说谁的做法就比较好。我根据自己的项目组织习惯,发布了一个项目dj-scaffold。...

在Python中合并字典模块ChainMap的隐藏坑【推荐】

在Python中合并字典模块ChainMap的隐藏坑【推荐】

在Python中,当我们有两个字典需要合并的时候,可以使用字典的 update 方法,例如: a = {'a': 1, 'b': 2} b = {'x': 3, 'y': 4} a....