從今天開(kāi)始,打算系統(tǒng)的學(xué)習(xí)一遍python3油湖。有感興趣的可以跟我一起學(xué)饰豺,每周至少更新四次晦闰。
1.?Python的3.0版本
Python 3.0 final was released on December 3rd, 2008.Python 3.0 (a.k.a. "Python 3000" or "Py3k") is a new version of the language that is incompatible with the 2.x line of releases. The language is mostly the same, but many details, especially how built-in objects like dictionaries and strings work, have changed considerably, and a lot of deprecated features have finally been removed. Also, the standard library has been reorganized in a few prominent places.
Python的3.0版本嚣鄙,常被稱為Python 3000吻贿,或簡(jiǎn)稱Py3k。相對(duì)于Python的早期版本哑子,這是一個(gè)較大的升級(jí)廓八。
2.?Python2.x與3??.x版本區(qū)別
a.?print 函數(shù)
print語(yǔ)句沒(méi)有了,取而代之的是print()函數(shù)赵抢。
原:print?? 5
改為:print ( 5 )
b.?Unicode
Python 2 有 ASCII str() 類(lèi)型,unicode() 是單獨(dú)的声功,不是 byte 類(lèi)型》橙矗現(xiàn)在, 在 Python 3先巴,我們最終有了 Unicode (utf-8) 字符串其爵,以及一個(gè)字節(jié)類(lèi):byte 和 bytearrays。
c. try except 語(yǔ)句的變化
原:try: ? ? ? ? ?
?????????????????......????
????????except??? Exception, e :????????
????????????????......
改為:try:?????????
? ? ? ? ? ? ? ? ?......????
????????????except??? Exception?as?e :????????
? ? ? ? ? ? ? ? ? ......
d.?range 與 xrange
在 Python 2 中 xrange() 創(chuàng)建迭代對(duì)象的用法是非常流行的伸蚯。比如: for 循環(huán)或者是列表/集合/字典推導(dǎo)式摩渺。
原:xrange( 0, 4 )適用于 for 循環(huán)的變量控制
改為:range(0, 4)
e.?不等運(yùn)算符
Python 2.x中不等于有兩種寫(xiě)法 != 和 <>
Python 3.x中去掉了<>, 只有!=一種寫(xiě)法
f.?去掉了repr表達(dá)式``
Python 2.x 中反引號(hào)``相當(dāng)于repr函數(shù)的作用
Python 3.x 中去掉了``這種寫(xiě)法,只允許使用repr函數(shù)
g.?從鍵盤(pán)錄入一個(gè)字符串
原:raw_input( "請(qǐng)輸入一個(gè)整型:" )?
改為: input( "請(qǐng)輸入一個(gè)整型:" )
h.?打開(kāi)文件
原:file( ..... )或open(.....)
改為:只能用open(.....)
這些大概是常用到的剂邮,還有很多其他的區(qū)別摇幻,可以自己了解一下,后面用到還會(huì)再說(shuō)挥萌。