print函数
在python2中,print只是一个关键字,但是在3.x中,print 是一个函数。
定义: print(*objects, sep=' ', end='\n', file=sys.stdout); 参数: *objects-复数,一次可输出多个对象,用‘,’分开 sep – 用来间隔多个对象,默认值是一个空格。 end --用来设定以什么结尾。默认值是换行符 \n,可以换成其他字符串。 file – 要写入的文件对象。 无返回值。
所以想要把多个输出放在同一行,只需要设定end的内容即可。
一个例子:
print ("hello", end=" ") print("world")
输出结果为
立即学习“Python免费学习笔记(深入)”;
hello world
再比如输出斐波那契数列(
a, b = 0, 1while a <1000: print(a, end = ',') a, b = b, a+bprint('...')
输出结果为
立即学习“Python免费学习笔记(深入)”;
0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,...
以上就是python中怎么连写两个print语句的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号