https://github.com/ltoddy/Pyt...python
不少時候,有些人在介紹 Python
的時候會提到 The Zen of Python
:git
>>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
可是我不知道你須要多久才能作到 The Zen of Python
中說的.github
Python
真的優雅嗎, Python
真的簡潔嗎, 這是固然, 否則 The Zen of Python
怎麼會添加到標準庫中去.shell
不過在此以前,你須要更加的學習(畢竟不是一上來就什麼都會的), 明白 Python 的風格, 或者說須要本身不斷鍛鍊, 讓本身寫出來的 Python 代碼更加的 pythonic.less
在這裏, 我不會講述相似:ide
a, b = b, a l = [x * 2 for x in range(10)]
相似這種你本就應該在初學 Python
就應該熟練掌握的東西.函數
由於以上的一些feature確實可讓你的代碼更加pythonic
, 並且也是很是重要的.學習
在很早很早以前,曾經看到一個羣友問了一個問題:ui
有兩個list, 好比: one = [1, 2, 3], other = [2, 3, 4]
this
他想要獲得這樣的結果,把這兩個相加獲得: [3, 5, 7], 也就是對應下標的元素相加.
我當時想都沒想就回了一句: return [one[i] + other[i] for i in range(len())]
看上去不錯,是嗎?
固然不是. 若是這兩個list不相等怎麼辦?
而後我又給了一個方案: return list(map(lambda x, y: x + y, one, other))
不過, 這樣又很差了, 若是一個list長,一個list短,這個樣子寫,長的那個list多出來的數據就會被丟掉了.
因此我又思考了一下, 從新給出了最後結果: return list(starmap(lambda x, y: x + y, zip_longest(one, ther, fillvalue=0)))
你能想到我所說的最後一種方案嗎?
Python 究竟是一種什麼樣的語言, 說真的, 很難給 Python 下一個定義,由於它的範式實在太多:
Python is an interpreted, interactive, object-oriented programming language. (來自Python docs)
若是你真正理解這些 feature 是什麼, 那麼很是顯然的是, 來告訴我: why and when you use it. (畢竟我更傾向於實用, 我不是學院派)
固然,在最後的時候,我也會告訴一些學習途徑, 好比看什麼書能夠最快的提升你的能力, 也好比你應該從哪些地方去獲取你須要掌握的知識.