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

相关文章

python3模拟实现xshell远程执行liunx命令的方法

python3模拟实现xshell远程执行liunx命令的方法

依赖包:pip install paramiko 源码demo: from time import * import paramiko # 定义一个类,表示一台远端linux主机 c...

python保存log日志,实现用log日志画图

在神经网络训练中,我们常常需要画出loss function的变化图,log日志里会显示每一次迭代的loss function的值,于是我们先把log日志保存为log.txt文档,再利用...

python标识符命名规范原理解析

这篇文章主要介绍了python标识符命名规范原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 简单地理解,标识符就是一个名字,就...

理解python正则表达式

在python中,对正则表达式的支持是通过re模块来支持的。使用re的步骤是先把表达式字符串编译成pattern实例,然后在使用pattern去匹配文本获取结果。 其实也有另外一种方式,...

Python使用matplotlib实现绘制自定义图形功能示例

Python使用matplotlib实现绘制自定义图形功能示例

本文实例讲述了Python使用matplotlib实现绘制自定义图形功能。分享给大家供大家参考,具体如下: 一 代码 from matplotlib.path importPath...