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

相关文章

详解Python里使用正则表达式的ASCII模式

ASCII ASCII(American Standard Code for Information Interchange),是一种单字节的编码。计算机世界里一开始只有英文,而单字节可...

Python多线程及其基本使用方法实例分析

本文实例讲述了Python多线程及其基本使用方法。分享给大家供大家参考,具体如下: 学习Python的多线程(Multi-threading),至少应该要有进程与线程的基本概念,可以参考...

修改 CentOS 6.x 上默认Python的方法

最近在工作中遇到一个问题,就是有一个功能希望在各种服务器上实现,而服务器上的系统版本可能都不一样,有的是 CentOS 6.x,有的是 CentOS 7.x 。 需要说明的一点是,Cen...

对Tensorflow中权值和feature map的可视化详解

对Tensorflow中权值和feature map的可视化详解

前言 Tensorflow中可以使用tensorboard这个强大的工具对计算图、loss、网络参数等进行可视化。本文并不涉及对tensorboard使用的介绍,而是旨在说明如何通过代...

python 筛选数据集中列中value长度大于20的数据集方法

如果我有一个数据集,他的某个列名下面的value很长,我们需要筛选出,所有列名中value值字符串大于20的数据集。 其实比较简单啦,一句代码就可以搞定 #对该列进行强制的字符类型转...