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

yipeiwu_com6年前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使用requests模块实现显示下载进度的方法详解

本文实例讲述了Python3使用requests模块实现显示下载进度的方法。分享给大家供大家参考,具体如下: 一、配置request 1. 相关资料 请求关键参数:stream=True...

关于不懂Chromedriver如何配置环境变量问题解决方法

关于不懂Chromedriver如何配置环境变量问题解决方法

今天新学selenium,安装Chromedriver时翻看了许多网上资料,还有很多CSDN大神写的博客,大神们写东西很多都是一笔带过,让我这种新手有点不知所措,弄了好久才弄懂,具体该如...

python求绝对值的三种方法小结

python求绝对值的三种方法小结

如下所示: 1.条件判断 2.内置函数abs() 3.内置模块 math.fabs abs() 与fabs()的区别 abs()是一个内置函数,而fabs()在math模块中定义的。...

解决pycharm无法调用pip安装的包问题

问题:pycharm无法调用pip安装的包 原因:pycharm没有设置解析器 解决方法: 打开pycharm->File->Settings->Project Int...

python 正则表达式参数替换实例详解

正则表达式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配。 Python 自1.5版本起增加了re 模块,它提供 Perl 风格的正则表达式模式。 re 模块使...