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

yipeiwu_com5年前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设计】。

相关文章

Python中pygame安装方法图文详解

Python中pygame安装方法图文详解

本文实例讲述了Python中pygame安装方法。分享给大家供大家参考,具体如下: 这里主要描述一下我们怎样来安装pygame 可能很多人像我一样,发现了pygame是个好东东,但是就是...

Python类属性与实例属性用法分析

本文实例分析了Python类属性与实例属性用法。分享给大家供大家参考。具体如下: 类属性:类名.属性名  实例属性:实例.属性名 >>> class te...

Python 列表去重去除空字符的例子

如下所示: # x = ['c b a',"e d f"] # y = [] # for i in x: # for ii in i: # # print(ii) # if ii =...

关于python2 csv写入空白行的问题

关于python2 csv写入空白行的问题

如下所示: writer = csv.writer(open('xx.csv','w')) data = [('zzz', 20, 123456),('jojo', 10, 7890...

python实现图片变亮或者变暗的方法

python实现图片变亮或者变暗的方法

本文实例讲述了python实现图片变亮或者变暗的方法。分享给大家供大家参考。具体实现方法如下: import Image # open an image file (.jpg or....