python 有很多不同 function,因此我想在這篇寫所有 funtion 我會用到。我指的 function 不是傳 function,而是一些 libary function
Math
Datetime 時間
time
程式跑的時間
如果計算程式袍多就可以用這方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import time
# starting time start = time.time() # your code for i in range(1,60): print(i)
#endtime end = time.time() runtime=end - start print(" Runtime of the program is {runtime:%.8f}") print(f"Runtime of the program is {runtime:.5f}") #or print(f"Runtime of the program is {(end - start):.5f}")
datetime
今天日期
date.today 取今天日期
1 2 3
from datetime import date print(date.today()) #2021-05-12
datetime.datetime.today 取今天日期和時間
1 2 3 4
from datetime import date now=datetime.datetime.today() print(now) #2021-01-21 13:29:47.648666
date time datetime 取今天日期和時間
1 2 3 4 5 6 7
from datetime import date from datetime import time from datetime import datetime print(datetime.now()) #2021-05-12 16:38:03.287772 print (datetime.time(datetime.now())) #16:40:27.363532