Python 3.x中的新打印函数与Python 2打印语句相比的优点是什么? [英] What is the advantage of the new print function in Python 3.x over the Python 2 print statement?
本文介绍了Python 3.x中的新打印函数与Python 2打印语句相比的优点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我多次听说print是一个函数(3.x)比它是一个声明(2.x)要好。但为什么呢?
我对这是一个声明的粉丝,主要是因为它允许我输入两个较少的字符(即括号)。
我有兴趣看到print语句不会削减它的一些情况,而且函数更好。
解决方案
所有Jochen + Sven都说,加上:
在不能使用 print
的地方使用 print()
,例如:
[print(x)for x in range(10)]
I've heard several times that print being a function (3.x) is better than it being a statement (2.x). But why?
I was a fan of it being a statement mainly because it allowed me to type two less characters (ie, the parentheses).
I'd be interested to see some situations where the print statement just doesn't cut it, and a function is superior.
解决方案
Everything Jochen + Sven said, plus:
You can use print()
it in places where you can't use print
, such as:
[print(x) for x in range(10)]
这篇关于Python 3.x中的新打印函数与Python 2打印语句相比的优点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文