首頁 > 後端開發 > Python教學 > Python中關於input和raw_input的比較

Python中關於input和raw_input的比較

黄舟
發布: 2017-08-20 10:15:40
原創
1603 人瀏覽過

這篇文章主要介紹了Python中input與raw_input 之間的比較的相關資料,透過本文希望能幫助到大家,對於他們之間的使用方法和區別,需要的朋友可以參考下

Python中input與raw_input 之間的比較

input和raw_input都可以接收輸入,其差異如下所示:


#input假设用户输入的是合法的Python表达式
>>> name = input("what is your name?")
what is your name?ZJ
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "<string>", line 1, in <module>
NameError: name &#39;ZJ&#39; is not defined

#于是,必须这么使用,输入Python格式的字符串"ZJ"
>>> name = input("what is your name?")
what is your name? "ZJ"
>>> print name
ZJ
>>> 

#raw_input会把所有输入当作原始数据(raw data),然后将其放入字符串中
>>> name = raw_input("what is your name?")
what is your name?ZJ
>>> print name
ZJ
>>>
登入後複製

因此,一般情況下應盡可能的使用raw_input。

以上是Python中關於input和raw_input的比較的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
python - ubuntu16.04 lxml的報錯
來自於 1970-01-01 08:00:00
0
0
0
有辦法在PHP裡寫Python嗎?
來自於 1970-01-01 08:00:00
0
0
0
python scrapy爬蟲錯誤
來自於 1970-01-01 08:00:00
0
0
0
python相關問題求解決,有償
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板