成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Do you want to be a Python expert ? 前言

孫淑建 / 1046人閱讀

摘要:很多時候有些人在介紹的時候會提到但是我不知道你需要多久才能做到中說的真的優(yōu)雅嗎真的簡潔嗎這是當(dāng)然不然怎么會添加到標(biāo)準(zhǔn)庫中去不過在此之前你需要更加的學(xué)習(xí)畢竟不是一上來就什么都會的明白的風(fēng)格或者說需要自己不斷鍛煉讓自己寫出來的代碼更

Do you want to be a Python expert ?

https://github.com/ltoddy/Pyt...

很多時候,有些人在介紹 Python 的時候會提到 The Zen of Python :

>>> 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 中說的.

Python 真的優(yōu)雅嗎, Python 真的簡潔嗎, 這是當(dāng)然, 不然 The Zen of Python 怎么會添加到標(biāo)準(zhǔn)庫中去.

不過在此之前,你需要更加的學(xué)習(xí)(畢竟不是一上來就什么都會的), 明白 Python 的風(fēng)格, 或者說需要自己不斷鍛煉, 讓自己寫出來的 Python 代碼更加的 pythonic.

在這里, 我不會講述類似:

a, b = b, a

l = [x * 2 for x in range(10)]

類似這種你本就應(yīng)該在初學(xué) Python 就應(yīng)該熟練掌握的東西.

我更想講述的是:

data model class (dunder methods, protocol).

metaclass (Base/Derive class)

Decorators

Generators

Context Managers

因為以上的一些feature確實可以讓你的代碼更加pythonic, 而且也是非常重要的.


A problem

在很早很早之前,曾經(jīng)看到一個群友問了一個問題:

有兩個list, 比如: one = [1, 2, 3], other = [2, 3, 4]

他想要得到這樣的結(jié)果,把這兩個相加得到: [3, 5, 7], 也就是對應(yīng)下標(biāo)的元素相加.

我當(dāng)時想都沒想就回了一句: return [one[i] + other[i] for i in range(len())]

看上去不錯,是嗎?

當(dāng)然不是. 如果這兩個list不相等怎么辦?

然后我又給了一個方案: return list(map(lambda x, y: x + y, one, other))

不過, 這樣又不好了, 如果一個list長,一個list短,這個樣子寫,長的那個list多出來的數(shù)據(jù)就會被丟掉了.

所以我又思考了一下, 重新給出了最后結(jié)果: return list(starmap(lambda x, y: x + y, zip_longest(one, ther, fillvalue=0)))

你能想到我所說的最后一種方案嗎?


What is Python ?

Python 到底是一種什么樣的語言, 說真的, 很難給 Python 下一個定義,因為它的范式實在太多:

面向?qū)ο?/p>

過程式

面向協(xié)議

原型

也支持函數(shù)式的feature

Python is an interpreted, interactive, object-oriented programming language. (來自Python docs)

如果你真正理解這些 feature 是什么, 那么非常顯然的是, 來告訴我: why and when you use it. (畢竟我更傾向于實用, 我不是學(xué)院派)


當(dāng)然,在最后的時候,我也會告訴一些學(xué)習(xí)途徑, 比如看什么書可以最快的提高你的能力, 也比如你應(yīng)該從哪些地方去獲取你需要掌握的知識.

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/42515.html

相關(guān)文章

  • Python-Socket-Programming(1)

    摘要: Abstract Sockets are used nearly everywhere, but are one of the most severely misunderstood technologies around. This is a 10,000 foot overview of sockets. It’s not really a tutorial - you’ll s...

    animabear 評論0 收藏0
  • Python相對導(dǎo)入導(dǎo)致SystemError的解決方案(譯)

    摘要:相對導(dǎo)入相對導(dǎo)入使用模塊的決定它是否在一個包內(nèi)。當(dāng)你是用類似進行相對導(dǎo)入的時候,點表明在包的層次中上升多少。所以,你不能在交互式會話中直接使用任何相對導(dǎo)入。 源題目與答案地址如下http://stackoverflow.com/questions/14132...。下面是我的翻譯(看作機翻也行),以及原文。 這個問題是如何解決在相對導(dǎo)入的時候,如果出現(xiàn)System Error的時候的解...

    ethernet 評論0 收藏0
  • 打造數(shù)據(jù)科學(xué)作品集:搭建一個數(shù)據(jù)科學(xué)博客

    摘要:讀完本文,你將學(xué)會如何使用靜態(tài)網(wǎng)站生成器,搭建一個屬于自己的博客,用來展示數(shù)據(jù)科學(xué)作品。靜態(tài)網(wǎng)站基本上,一個靜態(tài)網(wǎng)站就是一個全是文件的文件夾。建立靜態(tài)網(wǎng)站的一種方法是手寫,然后上傳所有的文件到服務(wù)器。 這是「打造數(shù)據(jù)科學(xué)作品集」系列文章的第二篇。如果你喜歡該系列,而且想知道下一篇文章什么時候發(fā)布,你可以訂閱我們。讀完本文,你將學(xué)會如何使用 Pelican 靜態(tài)網(wǎng)站生成器,搭建一個屬于...

    iamyoung001 評論0 收藏0
  • How did I install Youcompleteme

    I always want imporve my skills on VIM. Thus recently I spent two days on setting up a VIM IDE for C/C++ proprogramming. Below are some useful steps for YCM. Specifications Mac InfoOS X Yosemite Versi...

    TalkingData 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<