久久人人精品,亚洲少妇一区,欧美黄色免费网站,樱桃成人精品视频在线播放

您現(xiàn)在所在的位置:首頁(yè) >學(xué)習(xí)資源 > Python全棧+人工智能入門教材 > Python基礎(chǔ)入門教程55:Python input() 函數(shù)

Python基礎(chǔ)入門教程55:Python input() 函數(shù)

來(lái)源:奇酷教育 發(fā)表于:

Python基礎(chǔ) Python教程 Python入門

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

  python input() 相等于 eval(raw_input(prompt)) ,用來(lái)獲取控制臺(tái)的輸入。

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

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

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

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

  函數(shù)語(yǔ)法

  input([prompt])

  參數(shù)說(shuō)明:

  無(wú)

  實(shí)例

  input() 需要輸入 python 表達(dá)式

  >>>a = input("input:") input:123 # 輸入整數(shù) >>> type(a) <type 'int'> # 整型 >>> a = input("input:") input:"runoob" # 正確,字符串表達(dá)式 >>> type(a) <type 'str'> # 字符串 >>> a = input("input:") input:runoob # 報(bào)錯(cuò),不是表達(dá)式 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1, in <module> NameError: name 'runoob' is not defined <type 'str'>raw_input() 將所有輸入作為字符串看待

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

主站蜘蛛池模板: 竹溪县| 资中县| 萨迦县| 和林格尔县| 嘉祥县| 宁陵县| 海门市| 鹿邑县| 额敏县| 耿马| 房产| 阳信县| 辰溪县| 沐川县| 图木舒克市| 鹤山市| 鹤岗市| 芜湖市| 淮南市| 锡林郭勒盟| 平乡县| 黄骅市| 西充县| 会东县| 沂南县| 临朐县| 永和县| 湖北省| 台中县| 双峰县| 延吉市| 青州市| 芜湖县| 金秀| 榆树市| 高碑店市| 瑞丽市| 荃湾区| 柘城县| 麟游县| 阿拉尔市|