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数据类型之Set集合实例详解

本文实例讲述了Python数据类型之Set集合。分享给大家供大家参考,具体如下: set集合 1.概述 set与dict类似,但set是一组key的集合,与dict的区别在于set不存储...

Python中__init__和__new__的区别详解

__init__ 方法是什么? 使用Python写过面向对象的代码的同学,可能对 __init__ 方法已经非常熟悉了,__init__ 方法通常用在初始化一个类实例的时候。例如:...

python微信跳一跳系列之棋子定位像素遍历

python微信跳一跳系列之棋子定位像素遍历

前言 在前几篇博客中,分别就棋子的颜色识别、模板匹配等定位方式进行了介绍和实践,这一篇博客就来验证一下github中最热门的跳一跳外挂中采用的像素遍历的方法。 方法说明 像素遍历的实质依...

python 实现UTC时间加减的方法

如下所示: #!/usr/bin/env python # -*- coding:utf-8 -*- import datetime time_delta = datetime.t...

老生常谈进程线程协程那些事儿

老生常谈进程线程协程那些事儿

一、进程与线程 1.进程 我们电脑的应用程序,都是进程,假设我们用的电脑是单核的,cpu同时只能执行一个进程。当程序出于I/O阻塞的时候,CPU如果和程序一起等待,那就太浪费了,cpu会...