首頁  >  文章  >  後端開發  >  Python 2.7與Python 3.7區別

Python 2.7與Python 3.7區別

little bottle
little bottle轉載
2019-04-08 10:24:114831瀏覽

今天,我將帶大家去看看Python 2.7與Python 3.7這兩個版本差異。

Python 2.7與Python 3.7區別

區別一:print語法使用

Python2.7   print語法使用   >>> print "Hello Python"       

Python3.7   print語法使用   >>> print("Hello Python")

範例:在Python 3.7.0使用雙引號觸發SyntaxError異常機制  提示Did you mean print("Hello mean print("Hello Python3.7")  

Python 2.7與Python 3.7區別

 print 換行與不換行區別

 python  2.7  print 不換行使用","即可

Python 2.7與Python 3.7區別

 python 3.7 print 不換行使用end=""

 Python 2.7與Python 3.7區別

 區別二: raw_input()和input()

 Python 2.7  raw_input()  input() 都存在可用    raw_input()接收字串string  input()接收數字int /flot.

 Python 3.7  raw 格式回傳string

Python 2.7與Python 3.7區別

Python 2.7與Python 3.7區別

區隔三:函數cmp()

python 2.7   cmp(x,y)函數用於比較2個對象,如果x y 返回1

python3.7    cmp()已經不存在了,如果你需要實作比較功能,需要引入operator 模組,適合任何物件

>>> import operator>>> operator.eq('hello', 'name');False>>> operator.eq('hello', 'hello');True

區別四:string 字母大小寫字串

string.letters:包含所有字母(大寫或小寫)的字串

Python 3.0中,string.ascii_letters.

【建議課程:Python欄位課程

以上是Python 2.7與Python 3.7區別的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:cnblogs.com。如有侵權,請聯絡admin@php.cn刪除