中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

Python input() 函數(shù)

Python 內(nèi)置函數(shù) Python 內(nèi)置函數(shù)

Python3.x 中 input() 函數(shù)接受一個標(biāo)準(zhǔn)輸入數(shù)據(jù),返回為 string 類型。

Python2.x 中 input() 相等于 eval(raw_input(prompt)) ,用來獲取控制臺的輸入。

raw_input() 將所有輸入作為字符串看待,返回字符串類型。而 input() 在對待純數(shù)字輸入時具有自己的特性,它返回所輸入的數(shù)字的類型( int, float )。

注意:input() 和 raw_input() 這兩個函數(shù)均能接收 字符串 ,但 raw_input() 直接讀取控制臺的輸入(任何類型的輸入它都可以接收)。而對于 input() ,它希望能夠讀取一個合法的 python 表達(dá)式,即你輸入字符串的時候必須使用引號將它括起來,否則它會引發(fā)一個 SyntaxError 。

除非對 input() 有特別需要,否則一般情況下我們都是推薦使用 raw_input() 來與用戶交互。

注意:python3 里 input() 默認(rèn)接收到的是 str 類型。

函數(shù)語法

input([prompt])

參數(shù)說明:

  • prompt: 提示信息

實(shí)例

Python2.x: input() 需要輸入 python 表達(dá)式

>>>a = input("input:") input:123 # 輸入整數(shù) >>> type(a) <type 'int'> # 整型 >>> a = input("input:") input:"json" # 正確,字符串表達(dá)式 >>> type(a) <type 'str'> # 字符串 >>> a = input("input:") input:json # 報錯,不是表達(dá)式 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1, in <module> NameError: name 'json' is not defined <type 'str'>

Python2.x: raw_input() 將所有輸入作為字符串看待

>>>a = raw_input("input:") input:123 >>> type(a) <type 'str'> # 字符串 >>> a = raw_input("input:") input:json >>> type(a) <type 'str'> # 字符串 >>>

更多內(nèi)容

Python3.x input 說明

Python2.x 和 Python3.x 中 raw_input( ) 和 input( ) 區(qū)別

Python 內(nèi)置函數(shù) Python 內(nèi)置函數(shù)

其他擴(kuò)展