Python 3.x 中的新打印函数与 Python 2 打印语句相比有什么优势? [英] What is the advantage of the new print function in Python 3.x over the Python 2 print statement?

查看:15
本文介绍了Python 3.x 中的新打印函数与 Python 2 打印语句相比有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我多次听说 print 作为函数 (3.x) 比作为语句 (2.x) 更好.但为什么?

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).

我很想看看在某些情况下,print 语句并没有削减它,而函数却更胜一筹.

I'd be interested to see some situations where the print statement just doesn't cut it, and a function is superior.

推荐答案

一切来自 Jochen 的回答Sven 的回答,加上:

Everything from Jochen's answer and Sven's answer, plus:

可以在不能使用print的地方使用print(),比如:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆