亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

請打神指教,為什么我的運行結果打印了無數次 t ?

import time

def performance(unit):
??? def performance1(f):
??????? def performance2(*args, **kw):
??????????? t = time.ctime() *1000 if unit =='ms' else time.time()
??????????? print 'call '+f.__name__+'() in',t,unit
??????????? return f (*args, **kw)
??????? return performance2
??? return performance1
@performance('ms')
def factorial(n):
??? return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)


正在回答

1 回答

? t = time.ctime() *1000 if unit =='ms' else time.time()

首先題目要求是獲取計算時間

第二time.ctime()返回易讀的字符串模式的當前時間

?t = time.ctime() *1000就肯定會出錯,去掉*1000就不會打印了無數次 t


0 回復 有任何疑惑可以回復我~
#1

人間世支離疏

*1000就是把當前時間打印1000次,所以會出現打印無數t
2019-05-07 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
python進階
  • 參與學習       255563    人
  • 解答問題       3038    個

學習函數式、模塊和面向對象編程,掌握Python高級程序設計

進入課程

請打神指教,為什么我的運行結果打印了無數次 t ?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號