總結一個python招聘測試題

關於C/C++/Java什麼的面試題網上很多,一抓一大把,但是關於python的就少多了。偶然從網上發現一篇關於python招聘測試題的,還給出了答案的相關資料,順手轉來,供以後學校參考。

原帖:http://www.douban.com/group/topic/28872729/

問題:

1. 是否瞭解動態語言的鴨子模型? 

2. 是否瞭解可變參數與關鍵字參數? 

3. 對函數式編程有初步瞭解。 

4. 是否知道列表生成式? 

5. 是否知道lambda/decorator/slots? 

6. 爲什麼要把缺省參數設爲immutable? 

7. 是否知道Mixin? 

8. 是否知道WSGI接口? 

9. 是否知道異步框架如gevent/tornado? 

10. 是否深入瞭解過Python的GC和GIL?


答案相關資料鏈接:

動態語言的鴨子模型
http://zh.wikipedia.org/wiki/%E9%B8%AD%E5%AD%90%E7%B1%BB%E5%9E%8B
有python中‘*’和‘+’複用的介紹,wiki裏面的例子很好。

可變參數與關鍵字參數
http://blog.csdn.net/FeiSan/article/details/1729905
http://www.pythonclub.org/functions/args-kwargs 


函數式編程有初步瞭解 


列表生成式: generator
http://wiki.python.org/moin/Generators
http://docs.python.org/glossary.html#term-generator
Python官方文檔介紹較少,前面wiki的鏈接講解很詳細,引用的例子也很好。官方文檔裏面用生成器實現一個反序函數,有更簡便的例子:stackoverflow上面有提問者求教關於迴文的python實現,答案爲:palindrome[::-1]。
http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for
Stackoverflow上面的問題,什麼場景下用生成器?
第二個答案很好,介紹了fibnacci數列優化。利用yield,函數無return。
http://www.cnblogs.com/moinmoin/archive/2011/03/10/lsit-comprehensions-generators.html
文章價值不大,這段話還算易於理解:
“生成器表達式並不真正創建數字列表, 而是返回一個生成器,這個生成器在每次計算出一個條目後,把這個條目“產生”(yield)出來。 生成器表達式使用了“惰性計算”(lazy evaluation,也有翻譯爲“延遲求值”,我以爲這種按需調用call by need的方式翻譯爲惰性更好一些),只有在檢索時才被賦值( evaluated),所以在列表比較長的情況下使用內存上更有效。A generator object in python is something like a lazy list. The elements are only evaluated as soon as you iterate over them. ”

關於generator以及iterator有一個很好的例子
http://diveintopython3.ep.io/generators.html 這一章定義了一個plura函數,用來把單數單詞轉換成複數
http://diveintopython3.ep.io/iterators.html#a-plural-rule-iterator這是對上一個例子的擴展;這兩部分對plura函數做了6個版本,一步步講解,非常好

lambda/decorator/slots
關於decorator的教程:
http://www.thumbtack.com/engineering/a-primer-on-python-decorators/
用decorator,存儲已經計算的fibnacci數,減少計算,提高效率。
http://stackoverflow.com/questions/739654/understanding-python-decorators
Stackoverflow的提問,第二個答案很神奇。
http://news.ycombinator.com/item?id=3830185

有關slots
http://stackoverflow.com/questions/472000/python-slots
What the hell is a slot?
http://www.reddit.com/r/Python/comments/8yqj4/python_what_the_hell_is_a_slot/
http://www.elfsternberg.com/2009/07/06/python-what-the-hell-is-a-slot/

爲什麼要把缺省參數設爲immutable
http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument
Stackoverflow上最佳答案提到的鏈接:
http://effbot.org/zone/default-values.htm
Chrome的一個python shell插件提供了python2.5.2的環境,試驗裏面的代碼,每一次函數的id不同。本機python2.7.2的環境和教程上面的結果相同。
怎麼要確保缺省參數未改變?
def myfunc(value=sentinel):
if value is sentinel:
value = expression
# use/modify value here

Mixin
http://stackoverflow.com/questions/2582289/what-is-the-difference-between-a-mixin-and-the-decorator-pattern
http://stackoverflow.com/questions/4139508/in-python-can-one-implement-mixin-behavior-without-using-inheritance
http://stackoverflow.com/questions/9087072/how-do-i-create-a-mixin-factory-in-python
Blogs:
Mixin 掃盲班
http://blog.csdn.net/lanphaday/article/details/1656969
Using Mix-ins with Python
http://www.linuxjournal.com/article/4540
Mixins considered harmful/1
http://www.artima.com/weblogs/viewpost.jsp?thread=246341
Mixins considered harmful/2
http://www.artima.com/weblogs/viewpost.jsp?thread=246483

WSGI接口
WSGI Tutorial | Web Python
http://webpython.codepoint.net/wsgi_tutorial
wsgi-tutorial (網頁特效很酷)
http://archimedeanco.com/wsgi-tutorial/

知道異步框架如gevent/tornado

深入瞭解過Python的GC和GIL

內存管理與垃圾回收機制
http://docs.python.org/library/gc.html
Learning Python 第六章介紹python garbage cellocting機制:
http://books.google.com.hk/books?id=1HxWGezDZcgC&lpg=PP1&dq=inauthor%3A%22Mark%20Lutz%22&;hl=zh-CN&pg=PA148#v=onepage&q&f=false

Dabeaz: An Inside Look at the GIL Removal Patch of Lore
Guido van Rossum在 Google+ 上分享了此內容,2011年10月1日
http://dabeaz.blogspot.com/2011/08/inside-look-at-gil-removal-patch-of.html
Understanding the Python GIL
http://www.dabeaz.com/GIL/




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章