更新:2020-11-02 11:31
大小:1.1M
下載地址掃描二維碼安裝到手機
Python3.2.3官方文檔(中文版) 由筆者自己翻譯
學習Python 2還是Python 3?
羅振宇在今年的跨年演講,《時間的朋友》中有個觀點,大意是說,人們都有一種受虐情節,有時候希望別人對他粗暴一點。為此,他還舉了兩個例子,分別是“喬布斯對待消費者的態度”和“和菜頭不尊重他的飲食需求”,末了還很享受的來一句:我愛死他了,對我再粗暴一點好不好!
看到很多新同學在學習Python的過程中,猶豫學習Python 2還是學習Python 3而遲遲不行動,白白地浪費了大把時間,錯過了升職加薪的機會,我真心覺得非常遺憾。所以,我忍不住想對大家粗暴一次,給大家一個粗暴而又正確的答案:
應該學習Python 2還是Python 3?
都要學!
這個答案可能很出乎意料,也很容易反駁,例如:
Python 3 才是Python的未來
Python 官方都建議指直接學習Python 3
Python 2 只維護到2020年
真的是這樣嗎?作為一個在一線互聯網公司奮斗的工程師,也是一個多年的Python老手,大家不妨來看看我這么說的理由。
目錄
第一章Python初步介紹.
1.1Python用作計算器
1.1.1數字.
1.12字符串
1.1.3列表.
1.2初步走進編程之門.
第二章更多控制流程語句.
21if語句
2.2 for語句
23 range0方法.
2.4 break和continue語句和在循環中的else子旬
2.5 Pass語句.
2.6定義方法..
2.7更多關于方法定義
2.71默認參數值.
2.7.2關鍵字參數.
2.7.3可變參數列表
2.7.4拆分參數列表
2.7.5形式
2.7.6文檔字符串
2.8編碼風格.
第三章數據結構...
3.1列表
3.1.1把列表當做棧來用.
3.12把列表當做隊列來用.
3.1.3遞推式構造列表.
3.1.4嵌套列表推導式.
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發展歷史:
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!)
這個時間線很有意思。
3)python2和3的主要區別:
PYTHON 2 IS LEGACY, PYTHON 3 IS THE FUTURE. 因為python2即將被放棄維護。所以python2即將成為過去式(legacy)是顯而易見的。
PYTHON 2 AND PYTHON 3 HAVE DIFFERENT (SOMETIMES INCOMPATIBLE) LIBRARIES
二者支持的庫不一樣,而且轉換起來也比較麻煩(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)為什么公司會選擇從python2轉到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.
網友評論