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

后端 未结 5 838
我在风中等你
我在风中等你 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:59

    In python 2.7 print() is faster than print. Here a test make with Repl.it Python Console Online :

    import time
    
    start_time = time.time()
    print "lol"
    end_time = time.time()
    print(end_time - start_time)
    
    start_time_2 = time.time()
    print ("lol")
    end_time_2 = time.time()
    print(end_time_2 - start_time_2)
    
    print((end_time_2 - start_time_2) > (end_time - start_time))
    
    Python 2.7.10
    [GCC 4.8.2] on linux
    lol
    7.08103179932e-05
    lol
    1.00135803223e-05
    False
    

提交回复
热议问题