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

當咱們編程時,有時會出現以下錯誤:TypeError: '>' not supported between instances of 'str' and 'int'編程 以下圖:blog 這是由於input()返回的數據類型是str類型,不能直接和整數進行比較,必須先把str轉換成整型,使用int()方法:age = int(input ("請輸入你的年齡:"))input 改正以後爲:class
相關文章
相關標籤/搜索