日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

Python2和Python3中raw_input( )和input( )区别(附代码)

發(fā)布時(shí)間:2023/12/10 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python2和Python3中raw_input( )和input( )区别(附代码) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

備注:

1、在python2.x中raw_input( )和input( ),兩個(gè)函數(shù)都存在,其中區(qū)別為

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

input( )-----只能接收“數(shù)字”的輸入,在對(duì)待純數(shù)字輸入時(shí)具有自己的特性,它返回所輸入的數(shù)字的類型( int, float )

?

2、在python3.x中raw_input( )和input( )進(jìn)行了整合,去除了raw_input( ),僅保留了input( )函數(shù),其接收任意任性輸入,將所有輸入默認(rèn)為字符串處理,并返回字符串類型。

Python 2.3.4 (#1, Feb 2 2005, 11:44:13) [GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> user=raw_input("please input:") please input:wei # raw_input 輸入 字符串 成功 >>> user 'wei' >>> user=input("please input:") please input:123 # input 輸入 數(shù)字 成功(返回的是數(shù)字) >>> user 123 >>> user=raw_input("please input:") please input:111 # raw_input 輸入 數(shù)字 成功(返回的還是當(dāng)成字符串) >>> user '111' >>> user=input("please input:") please input:wei # input 輸入字符串 失敗 Traceback (most recent call last):File "<stdin>", line 1, in ?File "<string>", line 0, in ? NameError: name 'wei' is not defined Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> user=raw_input("please input:") #沒(méi)有了raw_input Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'raw_input' is not defined >>> user=input("please input:") please input:wei >>> user 'wei' >>> user=input("please input:") #input的輸出結(jié)果都是作為字符串 please input:123 >>> user '123'

?

?

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的Python2和Python3中raw_input( )和input( )区别(附代码)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。