python中print的不换行即时输出的快速解决方法

yipeiwu_com6年前Python基础

关于Python2.x和3.x带来的print不换行的问题:昨天有发过推文,利用end = 定义,解决了横向的小问题,但是由于屏幕显示的问题,若字符串长度过大,则会引起不便。两个或多个print做分割的情况下,如何保持依然横向输出,一般的是在print尾部加上逗号(,)但是在3.x下,则不行,需要使用end = "(something)",some signs like , . ; 'also you can put a word or str in"".

Example:

 

############################################
end1 = "j"
end2 = "u"
end3 = "s"
end4 = "t"
end5 = "t"
end6 = "e"
end7 = "s"
end8 = "t"
print(end1 + end2 + end3 + end4,end = " ")
print(end5 + end6 + end7 + end8)
############################################
Explain:
You can see that i put space between""
There will be something in your screen:
just test
All the codes was run in python 3.2,if you write the codes in pythons 2.x,like python2.7,
 
 
##################################################
end1 = "j"
end2 = "u"
end3 = "s"
end4 = "t"
end5 = "t"
end6 = "e"
end7 = "s"
end8 = "t"
print(end1 + end2 + end3 + end4,)
print(end5 + end6 + end7 + end8)
#################################################
that's all,in python 2.x
 
 
 
 
so the differences is:
3.2 end = " "
2.7 ,

以上这篇python中print的不换行即时输出的快速解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

将Dataframe数据转化为ndarry数据的方法

train_comb 为Dataframe数据: train_comb= train_comb.as_matrix() #得到values的ndarry train_comb =...

Python实现按当前日期(年、月、日)创建多级目录的方法

Python实现按当前日期(年、月、日)创建多级目录的方法

先看实际效果,现在时间2018.4.26 使用python脚本按照年月日生成多级目录,创建的目录可以将系统生成的日志文件放入其中,方便查阅,代码如下: #!/usr/bin/env...

python中metaclass原理与用法详解

本文实例讲述了python中metaclass原理与用法。分享给大家供大家参考,具体如下: 什么是 metaclass. metaclass (元类)就是用来创建类的类。在前面一篇文章《...

python3 map函数和filter函数详解

map()函数可以对一个数据进行同等迭代操作。例如: def f(x): return x * x r = map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9]...

Python3中的bytes和str类型详解

Python 3最重要的新特性之一是对字符串和二进制数据流做了明确的区分。文本总是Unicode,由str类型表示,二进制数据则由bytes类型表示。Python 3不会以任意隐式的方式...