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日志的配置文件路径问题

如下所示: import logging import logging.config logging.config.fileConfig(path) logger = logging...

不同版本中Python matplotlib.pyplot.draw()界面绘制异常问题的解决

前言 本文主要给大家介绍了关于不同版本中Python matplotlib.pyplot.draw()界面绘制异常的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍...

简单介绍Python中的decode()方法的使用

 decode()方法使用注册编码的编解码器的字符串进行解码。它默认为默认的字符串编码。 语法 以下是decode()方法的语法: str.decode(encoding=...

Django框架反向解析操作详解

Django框架反向解析操作详解

本文实例讲述了Django框架反向解析操作。分享给大家供大家参考,具体如下: 1. 定义: 随着功能的增加会出现更多的视图,可能之前配置的正则表达式不够准确,于是就要修改正则表达式,但是...

Python OrderedDict的使用案例解析

这篇文章主要介绍了Python OrderedDict的使用案例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 很多人认为python...