本篇文章為大家展示了python中的input有什么功能,代碼簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
在響水等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計制作、做網(wǎng)站 網(wǎng)站設(shè)計制作按需求定制制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站建設(shè),響水網(wǎng)站建設(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])
Python2.x: 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 # 報錯,不是表達(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'>
Python3.x
>>>a = input("input:") input:123 # 輸入整數(shù) >>> type(a) <class 'str'> # 字符串 >>> a = input("input:") input:runoob # 正確,字符串表達(dá)式 >>> type(a) <class 'str'> # 字符串
上述內(nèi)容就是python中的input有什么功能,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當(dāng)前文章:python中的input有什么功能
分享網(wǎng)址:http://muchs.cn/article8/ghgoop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、建站公司、手機(jī)網(wǎng)站建設(shè)、App設(shè)計、網(wǎng)站維護(hù)、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)