What is the difference between print and print() in python 2.7

后端 未结 5 826
我在风中等你
我在风中等你 2020-12-06 02:29

I am newbie on Python.

I run the following code on python 2.7 and I see different result when I use print or print(). What is the difference between these two functi

5条回答
  •  执笔经年
    2020-12-06 02:49

    In the first example you're printing tuple, but not calling print function. So the following is identical:

    a = ("box: ", box)
    print a
    

    In other words, in first example you've created a tuple and printed it. Different output, for different datatypes.

    There's supposed to be no significant difference between function and statement for your case, but for sake of future I'm strongly advice you to always use function (print()). However, if you're still interested in differences (not related to your case), with print function you can specify separator, end and where to output it as described in documentation.

提交回复
热议问题