总结一个python招聘测试题

来源:互联网 发布:visio是什么软件 编辑:程序博客网 时间:2024/06/04 18:40

关于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/




0 0
原创粉丝点击