Python中的一些面试问题小结


搜索关键字:
  • python interview question
  • Python 面试问题
参考链接:
参考问题列表:
  • 字符串的处理和正则表达式。
  • 如何操作json和xml数据。
  • 参数是如何传递的?传值还是传引用?(How are arguments passed – by reference of by value?)
  • 什么是列表和字典推导(list and dict comprehensions)?你能给个例子吗?
  • 什么是 PEP 8?
  • 如何计算列表里所有元素的和?如何计算列表里所有元素的乘积?
  • 你能列出列表(list)和元组(tuple)的区别吗?举例子说明用法的不同。
  • 你知道range和xrange的区别吗?
  • 请说出一些 python2.x 与 python3.x 之间的区别。
  • 什么是修饰器(Decorator)?你能说出它的用途吗?
  • with语句及其用法?
  • Package/Module的定义和区别,以及模块加载的原则。
  • 如何进行Package/Module的打包和分发?
  • 生成器(generator)的概念以及使用方式。
  • 你常用的 built-in 类型和函数有哪些?好处在哪?
  • 什么是 WSGI ?
  • 元类编程(metaclass)的概念,以及如何使用?

##

##

easy/intermediate
    #Python中的装饰器(decorator)是什么,有什么作用?
    What are Python decorators and how would you use them?
    #你如何解决项目中使用依赖于不同Python版本的第三方库的问题的?
    How would you setup many projects where each one uses different versions of Python and third party libraries?
    #PEP8是什么,你自己在编码时会考虑到其中的规范问题么?
    What is PEP8 and do you follow its guidelines when you're coding?
    #Python中的参数传递到底是值传递还是引用传递?
    How are arguments passed – by reference of by value? (easy, but not that easy, I'm not sure if I can answer this clearly)
    #列表推导式和字典推导式
    Do you know what list and dict comprehensions are? Can you give an example?
    #用3种不同的方法取每一个列表中的第三个元素
    Show me three different ways of fetching every third item in the list
    #列表和元组的不同之处在哪?
    Do you know what is the difference between lists and tuples? Can you give me an example for their usage?
    #Python2中range和xrange的不同之处
    Do you know the difference between range and xrange?
    #Python2和Python3的不同之处有哪些?
    Tell me a few differences between Python 2.x and 3.x?
    #with语句的使用
    The with statement and its usage.
    #如何避免重复引用?
    How to avoid cyclical imports without having to resort to imports in functions?
    #from xx import * 这样有什么不好?
    What's wrong with import all?
    #GIL的重要性
    Why is the GIL important? (This actually puzzles me, don't know the answer)
    #什么是特殊方法,它们如何工作的,举例说明
    What are "special" methods (<foo>), how they work, etc
    #你能像操作"first-class object"那样操作函数么?
    can you manipulate functions as first-class objects?
    #"class Foo" 和 "class Foo(object)" 的不同之处
    the difference between "class Foo" and "class Foo(object)"

tricky, smart ones
    #在Python中如何读取一个8G大小的文件?
    how to read a 8GB file in python?
    #你不喜欢Python中的什么特性/语法?
    what don't you like about Python?
    #如何独立将一个ascii码转换成整数而不使用内置方法或函数?
    can you convert ascii characters to an integer without using built in methods like string.atoi or int()? curious one

subjective ones
    #你在Python编码时使用Tab还是空格?
    do you use tabs or spaces, which ones are better?

Ok, so should I add something else or is the list comprehensive?

##

Python中module和package的不同之处
Python中的WSGI是什么?
Python的元类编程
Python中的修饰器(@decorator)
对Python中 *args 和 **kwargs 的解释

搜索关键字:python *args **kwargs

Python中参数是如何传递的?传值还是传引用?

回答:“都不是”,事实上 Python 里是传对象(a reference to an object)

搜索关键字:

python How are arguments passed

参考链接:
在Python中如何计算列表里所有元素的和?如何计算列表里所有元素的乘积?
#基本loop方式,sum函数方式,以及使用reduce函数
# the basic way
s = 0
for x in range(10):
	s += x

# the right way
s = sum(range(10))

# the other way
from operator import add
s = reduce(add, range(10))
你能列出列表(list)和元组(tuple)的区别吗?举例子说明用法的不同。

搜索关键字:python difference between list and tuple

参考链接:
参考解答:

列表和元组是 Python 里最基本的两个数据类型:

首先,列表对象是可变的(mutable),但元组不是;

其次,元组可被哈希(hashable),例如可以用作字典对象的键(key);

至于例子,地图上的地理坐标可以用二元组表示,而地图上的路径可以用坐标点列表来表示。

但也并不是所有的 tuple 都是可被hash的,比如:包含了list等不可hash的内容的tuple就无法被hash

=EOF=

,

《“Python中的一些面试问题小结”》 有 10 条评论

  1. 几道python面试题
    http://www.hi-roy.com/2017/07/21/%E5%87%A0%E9%81%93python%E9%9D%A2%E8%AF%95%E9%A2%98/
    `
    生成斐波那契数列并取前10项
    扩展一个列表,列表中的元素可能也包含列表
    创建一个类,并输出某个属性。如果这个属性存在则输出值,否则输出这个属性名的字符串

    简述py2和py3的区别
    python的垃圾回收机制
    python中多线程的方法,局限,以及有什么其他方式进行并发处理
    简述epoll、select、poll三种模型
    `

回复 a-z 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注