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

相关文章

pytorch中的transforms模块实例详解

pytorch中的transforms模块中包含了很多种对图像数据进行变换的函数,这些都是在我们进行图像数据读入步骤中必不可少的,下面我们讲解几种最常用的函数,详细的内容还请参考pyto...

用django设置session过期时间的方法解析

session的超时时间设置 settings中 SESSION_COOKIE_AGE=60*30 30分钟。 SESSION_EXPIRE_AT_BROWSER_CLOSE...

python中使用zip函数出现&lt;zip object at 0x02A9E418&gt;错误的原因

python中zip函数返回一个以元组为元素的列表,其中第 i 个元组包含每个参数序列的第 i 个元素。返回的列表长度被截断为最短的参数序列的长度。只有一个序列参数时,它返回一个1元组的...

浅谈Python接口对json串的处理方法

最近学习Python接口测试,对于接口测试完全小白。大概一周的学习成果进行总结。 1.接口测试: 目前涉及到的只是对简单单一的接口进行参数传递,得到返回自。 2.关于各种概念: 2.1...

set在python里的含义和用法

set在python里是什么意思? set是一组数,无序,内容又不能重复,通过调用set()方法创建: >>> s = set(['A', 'B', 'C'...