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

Python raw_input() 函數

Python 內置函數 Python 內置函數

python raw_input() 用來獲取控制臺的輸入。

raw_input() 將所有輸入作為字符串看待,返回字符串類型。

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

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

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

函數語法

raw_input([prompt])

參數說明:

  • prompt: 可選,字符串,可作為一個提示語。

實例

raw_input() 將所有輸入作為字符串看待

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

input() 需要輸入 python 表達式

>>>a = input("input:") input:123 # 輸入整數 >>> type(a) <type 'int'> # 整型 >>> a = input("input:") input:"json" # 正確,字符串表達式 >>> type(a) <type 'str'> # 字符串 >>> a = input("input:") input:json # 報錯,不是表達式 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'>

Python 內置函數 Python 內置函數

其他擴展