更新:2020-11-02 11:31
大。1.1M
下載地址掃描二維碼安裝到手機(jī)
Python3.2.3官方文檔(中文版) 由筆者自己翻譯
學(xué)習(xí)Python 2還是Python 3?
羅振宇在今年的跨年演講,《時(shí)間的朋友》中有個(gè)觀點(diǎn),大意是說,人們都有一種受虐情節(jié),有時(shí)候希望別人對(duì)他粗暴一點(diǎn)。為此,他還舉了兩個(gè)例子,分別是“喬布斯對(duì)待消費(fèi)者的態(tài)度”和“和菜頭不尊重他的飲食需求”,末了還很享受的來一句:我愛死他了,對(duì)我再粗暴一點(diǎn)好不好!
看到很多新同學(xué)在學(xué)習(xí)Python的過程中,猶豫學(xué)習(xí)Python 2還是學(xué)習(xí)Python 3而遲遲不行動(dòng),白白地浪費(fèi)了大把時(shí)間,錯(cuò)過了升職加薪的機(jī)會(huì),我真心覺得非常遺憾。所以,我忍不住想對(duì)大家粗暴一次,給大家一個(gè)粗暴而又正確的答案:
應(yīng)該學(xué)習(xí)Python 2還是Python 3?
都要學(xué)!
這個(gè)答案可能很出乎意料,也很容易反駁,例如:
Python 3 才是Python的未來
Python 官方都建議指直接學(xué)習(xí)Python 3
Python 2 只維護(hù)到2020年
真的是這樣嗎?作為一個(gè)在一線互聯(lián)網(wǎng)公司奮斗的工程師,也是一個(gè)多年的Python老手,大家不妨來看看我這么說的理由。
目錄
第一章Python初步介紹.
1.1Python用作計(jì)算器
1.1.1數(shù)字.
1.12字符串
1.1.3列表.
1.2初步走進(jìn)編程之門.
第二章更多控制流程語(yǔ)句.
21if語(yǔ)句
2.2 for語(yǔ)句
23 range0方法.
2.4 break和continue語(yǔ)句和在循環(huán)中的else子旬
2.5 Pass語(yǔ)句.
2.6定義方法..
2.7更多關(guān)于方法定義
2.71默認(rèn)參數(shù)值.
2.7.2關(guān)鍵字參數(shù).
2.7.3可變參數(shù)列表
2.7.4拆分參數(shù)列表
2.7.5形式
2.7.6文檔字符串
2.8編碼風(fēng)格.
第三章數(shù)據(jù)結(jié)構(gòu)...
3.1列表
3.1.1把列表當(dāng)做棧來用.
3.12把列表當(dāng)做隊(duì)列來用.
3.1.3遞推式構(gòu)造列表.
3.1.4嵌套列表推導(dǎo)式.
3.3元組和序列.
3.4 Set集合.
1)Python 3 取勝:
Now, in 2018, it’s more of a no-brainer: Python 3 is the clear winner for new learners or those wanting to update tudemheir skills. Here, we’ll cover why Python 3 is better, and why companies have been moving from Python 2 to 3 en masse.
2)python2和3發(fā)展歷史:
Python 2.0 was first released in 2000. Its latest version, 2.7, was released in 2010.
Python 3.0 was released in 2008. Its newest version, 3.6, was released in 2016, and version 3.7 is currently in development.
Although Python 2.7 is still widely used, Python 3 adoption is growing quickly. In 2016, 71.9% of projects used Python 2.7, but by 2017, it had fallen to 63.7%. This signals that the programming community is turning to Python 3–albeit gradually–when developing real-world applications.
Notably, on January 1, 2018, Python 2.7 will “retire” and no longer be maintained. (The clock is literally ticking!)
這個(gè)時(shí)間線很有意思。
3)python2和3的主要區(qū)別:
PYTHON 2 IS LEGACY, PYTHON 3 IS THE FUTURE. 因?yàn)閜ython2即將被放棄維護(hù)。所以python2即將成為過去式(legacy)是顯而易見的。
PYTHON 2 AND PYTHON 3 HAVE DIFFERENT (SOMETIMES INCOMPATIBLE) LIBRARIES
二者支持的庫(kù)不一樣,而且轉(zhuǎn)換起來也比較麻煩(complicated)
THERE IS BETTER UNICODE SUPPORT IN PYTHON 3
In Python 3, text strings are Unicode by default. In Python 2, strings are stored as ASCII by default–you have to add a “u” if you want to store strings as Unicode in Python 2.x.
This is important because Unicode is more versatile than ASCII. Unicode strings can store foreign language letters, Roman letters and numerals, symbols, emojis, etc., offering you more choices.
PYTHON 3 HAS IMPROVED INTEGER DIVISION:
In Python 2, if you write a number without any digits after the decimal point, it rounds your calculation down to the nearest whole number.
For example, if you’re trying to perform the calculation 5 divided by 2, and you type 5 / 2, the result will be 2 due to rounding. You would have to write it as 5.0 / 2.0 to get the exact answer of 2.5.
However, in Python 3, the expression 5 / 2 will return the expected result of 2.5 without having to worry about adding those extra zeroes.
This is one example of how Python 3 syntax can be more intuitive, making it easier for newcomers to learn Python programming.
THE TWO VERSIONS HAVE DIFFERENT PRINT STATEMENT SYNTAXES
This is only a syntactical difference–and some may consider it trivial–so it doesn’t affect the functionality of Python. That said, it is still a big and visible difference you should know about.
Essentially, in Python 3, the print statement has been replaced with a print () function.
4)為什么公司會(huì)選擇從python2轉(zhuǎn)到python3
As mentioned earlier, most companies are still using Python 2 for legacy reasons, but more and more companies are using Python 3, or beginning to make the switch from 2 to 3.
So, let’s look at Instagram and Facebook–two companies that have switched from Python 2 to 3 or are in the process of doing so–and why they chose to do so.
小編簡(jiǎn)評(píng):《出海吧》
下載 2020中國(guó)美妝地圖高清版 715KB /小編簡(jiǎn)評(píng):2020中國(guó)美
下載 陸加設(shè)計(jì)最新完整版 202.3M /小編簡(jiǎn)評(píng):陸加設(shè)計(jì)是
下載 Python爬取PPT模板小工具 14.4M /小編簡(jiǎn)評(píng):Python爬取
下載 我在7年后等著你游戲 125.2M /小編簡(jiǎn)評(píng):我在7年后等
下載 i-Spy Mini連接app 20.7M /小編簡(jiǎn)評(píng):1.打開手機(jī)
下載 月圓之夜終章完整版 333M /小編簡(jiǎn)評(píng):月圓之夜終
網(wǎng)友評(píng)論