Python之input與raw_input的區(qū)別

 input 接受合法的Python 表達式

     raw_input 將所有的輸入作為原始數(shù)據(jù),將其放入字符串中

     >>> name =  input("what's your name ?")

                    what's your name ?  Yellow
                    Traceback (most recent call last):
                    File "<pyshell#10>", line 1, in <module>
                    name = input("What's is your name ?")
                    File "<string>", line 1, in <module>
                    NameError: name 'yellow' is not defined

    >>> Yellow = "yellow"
    >>> name =  input("what's your name ?")

                    what's your name ?  Yellow

    >>> print "Hello, " + name
                    Hello, yellow

>>> input('Enter a number ')
                Enter a number 3
                3

             第一次輸入“Yellow”時,作為表達式,但是沒有定義,故報錯,如果輸入為正確表達式,則需要加單引號或雙引號,作為字符串表達式輸入。
             第二次定義了Yellow為表達式,并進行了賦值操作,所以再次輸入,為合法的表達式,故沒有報錯。
             第三次輸入數(shù)字3,作為數(shù)字,即合法的表達式,故沒有報錯。

             raw_input() 函數(shù)將所有輸入原始數(shù)據(jù),并放入字符串中,故不會報錯。

             >>> name = raw_input("What's is your name ?")
                            What's is your name ?Yellow
            >>> print "Hello, " + name
                            Hello, Yellow

本文題目:Python之input與raw_input的區(qū)別
本文鏈接:http://muchs.cn/article24/jpgoce.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)建站公司、App開發(fā)、網(wǎng)站改版微信小程序、網(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)

外貿(mào)網(wǎng)站建設(shè)