python——input()函數


在使用input()內置函數輸入數字時,要注意一點:

input()的返回值始終是字符串,所以type(number)永遠是<class 'str'>!

如:

>>> temp = input("請輸入一個數字:")
請輸入一個數字:3
>>> type(temp)
<class 'str'>

這一點一定要注意!!!如果接下來要使用數字時,要回用到強制類型轉化!

如下例子:

>>> temp = input("請輸入一個數字:")
請輸入一個數字:3
>>> type(temp)
<class 'str'>
>>> temp = int(temp)        
>>> type(temp)
<class 'int'>
>>> temp+2
5


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



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