原文:python的強制轉換(當出現 not supported between instances of 'str' and 'int' 的錯誤時)

當我們編程時,有時會出現如下錯誤:TypeError: gt not supported between instances of str and int 如下圖: 這是因為input 返回的數據類型是str類型,不能直接和整數進行比較,必須先把str轉換成整型,使用int 方法:age int input 請輸入你的年齡: 改正之后為: 這樣程序就達到了預期的效果了 ...

2017-09-16 17:13 0 33797 推薦指數:

查看詳情

 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM