新聞中心
python2.7與python3.7的區(qū)別:1、print語法的使用規(guī)則不同;2、“raw_input()”和“input()”方法的使用方式不同;3、cmp()函數(shù)的用途不同;4、string的使用方式不同。
創(chuàng)新互聯(lián)公司主營即墨網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app軟件開發(fā),即墨h5微信平臺小程序開發(fā)搭建,即墨網(wǎng)站營銷推廣歡迎即墨等地區(qū)企業(yè)咨詢
區(qū)別一:print語法使用
Python2.7 print語法使用 >>> print "Hello Python"
Python3.7 print語法使用 >>> print("Hello Python")
例子:在Python 3.7.0使用雙引號觸發(fā)SyntaxError異常機制 提示Did you mean print("Hello Python3.7")
print 換行和不換行區(qū)別
python 2.7 print 不換行使用","即可
python 3.7 print 不換行使用end=""
區(qū)別二: raw_input()和input()
Python 2.7 raw_input() input() 都存在 可使用 raw_input()接收字符串string input()接收數(shù)字int /flot.
Python 3.7 raw_input()不存在 僅存在input() 兩者合并 接收任意格式 返回string
區(qū)別三: 函數(shù)cmp()
python 2.7 cmp(x,y)函數(shù)用于比較2個對象,如果 x < y 返回 -1, 如果 x == y 返回 0, 如果 x > y 返回 1
python3.7 cmp()已經(jīng)不存在了,如果你需要實現(xiàn)比較功能,需要引入 operator 模塊,適合任何對象
>>> import operator
>>> operator.eq('hello', 'name');
False
>>> operator.eq('hello', 'hello');
True
區(qū)別四:string 字母 大小寫字符串
string.letters:包含所有字母(大寫或小寫)的字符串
Python 3.0中,string.ascii_letters.
推薦課程:中谷教育Python視頻教程
當前名稱:創(chuàng)新互聯(lián)Python教程:python2.7與python3.7的區(qū)別是什么
文章位置:http://www.dlmjj.cn/article/djjpddp.html


咨詢
建站咨詢

