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

相关文章

tensorflow实现对张量数据的切片操作方式

如下所示: import tensorflow as tf a=tf.constant([[[1,2,3,4],[4,5,6,7],[7,8,9,10]], [[11,1...

Python实现的购物车功能示例

Python实现的购物车功能示例

本文实例讲述了Python实现的购物车功能。分享给大家供大家参考,具体如下: 这里尝试用python实现简单的购物车程序。。。 基本要求: 用户输入工资,然后打印购物菜单 用户可以不断的...

跟老齐学Python之玩转字符串(3)

字符串就是一个话题中心。 给字符串编号 在很多很多情况下,我们都要对字符串中的每个字符进行操作(具体看后面的内容),要准确进行操作,必须做的一个工作就是把字符进行编号。比如一个班里面有5...

Python内置函数 next的具体使用方法

Python 3中的File对象不支持next()方法。 Python 3有一个内置函数next(),它通过调用其next ()方法从迭代器中检索下一个项目。 如果给定了默认值,则在迭代...

pandas ix &iloc &loc的区别

一开始自学Python的numpy、pandas时候,索引和切片把我都给弄晕了,特别是numpy的切片索引、布尔索引和花式索引,简直就是大乱斗。但是最近由于版本的问题,从之前的Pytho...