which of the following is invalid?
int('20.18')
float(20.18)
float('20.18')
int(20.18)
答案是int('20.18')
這題不就是格式強制轉換嗎?為什么第一個對,其他不對?
uj5u.com熱心網友回復:
就這個int('20.18') 不能成功, 其他3個都能成功.沒啥問題呀. 字串 '20.18' 轉成數字后不是整型, 會提示轉換失敗. int('20') 就可以成功. int(20.18) 也可以成功, 因為是浮點取整.
uj5u.com熱心網友回復:
int(float('20.18'))可以成功轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/68422.html
上一篇:第二行開始就看不懂了
下一篇:AttributeError: module 'matplotlib.pyplot' has no attribute 'show'
