Printing the time between 2 points in a program in Python

This question already has an answer here:

  • How to get current time in Python? 27 answers

  • import time
    s=time.time()
    question1 = input("What is your favorite game ?")
    e=time.time()
    print(e-s)
    

    time.time()返回自纪元以来的秒数,以浮点数表示。


    这个怎么样?

    from datetime import datetime
    start = datetime.now()
    question1 = input("What is your favorite game ?")
    end = datetime.now()
    print(str(end - start))
    
    链接地址: http://www.djcxy.com/p/40912.html

    上一篇: 你如何获得python的时间和日期?

    下一篇: 在Python中的程序中打印两个点之间的时间