直接上代码: import time t1 = time.time() """ """ t2 = time.time() t = t2 = t1 print('代码运行时间 {:.0f}分 {:.0f}秒'.format( t // 60, t % 60))