What is the advantage of the new print function in Python 3.x over the Python 2 print statement?

后端 未结 5 1691
感动是毒
感动是毒 2020-12-05 22:15

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

5条回答
  •  粉色の甜心
    2020-12-05 22:50

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

    You can use print() it in places where you can't use print, such as:

    [print(x) for x in range(10)]
    

提交回复
热议问题