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编码问题汇总

python3编码问题汇总

这两天写了个监测网页的爬虫,作用是跟踪一个网页的变化,但运行了一晚出现了一个问题。。。。希望大家不吝赐教! 我用的是python3,错误在对html response的decode时抛出...

Python数据可视化:顶级绘图库plotly详解

Python数据可视化:顶级绘图库plotly详解

有史以来最牛逼的绘图工具,没有之一 plotly是现代平台的敏捷商业智能和数据科学库,它作为一款开源的绘图库,可以应用于Python、R、MATLAB、Excel、JavaScript...

linux环境下python中MySQLdb模块的安装方法

前言 最近开始学习python数据库编程后,在了解了基本概念,打算上手试验一下时,卡在了MYSQLdb包的安装上,折腾了半天才解决。记录一下我在linux中安装此包遇到的问题。 系统是u...

Python判断中文字符串是否相等的实例

Python判断中文字符串是否相等的实例

Python判断两个相等的中文字符串为false,将两个待比较的字符串都把unicode编码设为‘utf-8'也不能解决问题,具体原因如下: 1.首先查看待比较两个字符串的编码格式 ,使...

python Pexpect 实现输密码 scp 拷贝的方法

在服务器A上的程序用到服务器B上的文件data,并且需要定期更新文件。 但是直接在bash文件中使用 scp -P 1000 192.168.199.10:/temp/data /t...