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中函数的可变参数

前言 在Python中定义函数,可以用必选参数、默认参数、可变参数和关键字参数,这4种参数都可以一起使用,或者只用其中某些,但是请注意,参数定义的顺序必须是:必选参数、默认参数、可变参...

Python中的descriptor描述器简明使用指南

当定义迭代器的时候,描述是实现迭代协议的对象,即实现__iter__方法的对象。同理,所谓描述器,即实现了描述符协议,即__get__, __set__, 和 __delete__方法的...

Python3.6.0+opencv3.3.0人脸检测示例

Python3.6.0+opencv3.3.0人脸检测示例

网上有很多关于Python+opencv人脸检测的例子,并大都附有源程序。但是在实际使用时依然会遇到这样或者那样的问题,在这里给出常见的两种问题及其解决方法。 先给出源代码:(如下)...

Python 查找list中的某个元素的所有的下标方法

如下所示: #!/usr/bin/env python #_*_ coding:utf-8 _*_ name = ['hello', 'world', 'a', 'b', 'c',...

Python数据报表之Excel操作模块用法分析

Python数据报表之Excel操作模块用法分析

本文实例讲述了Python数据报表之Excel操作模块用法。分享给大家供大家参考,具体如下: 一 点睛 Excel是当今最流行的电子表格处理软件,支持丰富的计算函数及图表,在系统运营方面...