python interview questions
referce:python interview questions top 50
refercence:python interview questions top 15
summary
Q:
what is python?
A:
- Python is an interpreted language. Python does not need to be compiled before it is run. Other interpreted languages include PHP and Ruby
- Python is dynamically typed, this means that you don't need to state the types of variables when you declare them or anything like that.
- Writing Python code is quick but running it is often slower than compiled languages. Fortunately, Python allows the inclusion of C based extensions so bottlenecks can be optimised away and often are. The numpy package is a good example of this, it's really quite quick because a lot of the number crunching it does isn't actually done by Python
Q: data type
A0 = dict(zip(('a','b','c','d','e'),(1,2,3,4,5)))
A1 = range(10)
A2 = sorted([i for i in A1 if i in A0])
A3 = sorted([A0[s] for s in A0])
A4 = [i for i in A1 if i in A3]
A5 = {i:i*i for i in A1}
A6 = [[i,i*i] for i in A1]
A:
A0 = {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4} # the order may vary
A1 = range(0, 10) # or [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] in python 2
A2 = []
A3 = [1, 2, 3, 4, 5]
A4 = [1, 2, 3, 4, 5]
A5 = {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}
A6 = [[0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81]]
Q:
Python and multi-threading
A:
Python doesn't allow multi-threading in the truest sense of the word. Python has a construct called the Global Interpreter Lock (GIL). The GIL makes sure that only one of your 'threads' can execute at any one time.
Q:
Version control
A:Version Control helps with keeping track of who made what change to the code base; finding out when bugs were introduced to the code; keeping track of versions and releases of your software; distributing the source code amongst team members; deployment and certain automations. It allows you to roll your code back to before you broke it which is great on its own
Q:
What does this stuff mean: *args, **kwargs?
A:
Use *args when we aren't sure how many arguments are going to be passed to a function, or if we want to pass a stored list or tuple of arguments to a function. **kwargs is used when we dont know how many keyword arguments will be passed to a function, or it can be used to pass the values of a dictionary as keyword arguments. The identifiers args and kwargs are a convention.
def f(*args,**kwargs): print(args, kwargs)
l = [1,2,3]
t = (4,5,6)
d = {'a':7,'b':8,'c':9}
f(l)
f(d)
f(l,d)
f(*l,**d)
output:
([1, 2, 3],) {}
({'a': 7, 'b': 8, 'c': 9},) {}
([1, 2, 3], {'a': 7, 'b': 8, 'c': 9}) {}
(1, 2, 3) {'a': 7, 'b': 8, 'c': 9}
Q:
Decorator
A:
@my_decorator
def my_func(stuff):
do_things
equivalent to
def my_func(stuff):
do_things
my_func = my_decorator(my_func)
Q:
Python's garbage collection mechanism
A:
- Python maintains a count of the number of references to each object in memory. If a reference count goes to zero then the associated object is no longer live and the memory allocated to that object can be freed up for something else
- recently created objects are more likely to be dead. As objects are created, the garbage collector assigns them to generations. Each object gets one generation, and younger generations are dealt with first.
count run efficiency
import cProfile
cProfile.run("func('para')")
Q:
What is monkey patching in Python?
A:
# code at m.py
class MyClass:
def f(self):
print "f()"
import m
def monkey_f(self):
print "monkey_f()"
m.MyClass.f = monkey_f
obj = m.MyClass()
obj.f()
output:
monkey_f()
conclusion: the term monkey patch only refers to dynamic modifications of a class or module at run-time.
python interview questions的更多相关文章
- WCF学习系列二---【WCF Interview Questions – Part 2 翻译系列】
http://www.topwcftutorials.net/2012/09/wcf-faqs-part2.html WCF Interview Questions – Part 2 This WCF ...
- [译]Node.js Interview Questions and Answers (2017 Edition)
原文 Node.js Interview Questions for 2017 什么是error-first callback? 如何避免无止境的callback? 什么是Promises? 用什么工 ...
- WCF学习系列三--【WCF Interview Questions – Part 3 翻译系列】
http://www.topwcftutorials.net/2012/10/wcf-faqs-part3.html WCF Interview Questions – Part 3 This WCF ...
- WCF学习系列四--【WCF Interview Questions – Part 4 翻译系列】
WCF Interview Questions – Part 4 This WCF service tutorial is part-4 in series of WCF Interview Qu ...
- [转]Design Pattern Interview Questions - Part 4
Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, te ...
- [转]Design Pattern Interview Questions - Part 2
Interpeter , Iterator , Mediator , Memento and Observer design patterns. (I) what is Interpreter pat ...
- [转]Design Pattern Interview Questions - Part 3
State, Stratergy, Visitor Adapter and fly weight design pattern from interview perspective. (I) Can ...
- [转]Design Pattern Interview Questions - Part 1
Factory, Abstract factory, prototype pattern (B) What are design patterns? (A) Can you explain facto ...
- 101+ Manual and Automation Software Testing Interview Questions and Answers
101+ Manual and Automation Software Testing Interview Questions and Answers http://www.softwaretesti ...
随机推荐
- Java中对类的主动引用和被动引用
1.遇到new,getstatic,putstatic,invokestatic这4条字节码指令时,类如果没初始化就会被初始化,创建对象,读取或设置静态字段,调用静态方法. 2.反射 3.子类初始化前 ...
- 51nod 1138 【数学-等差数列】
思路: 很显然每个连续的序列都是等差数列, 那么我们利用等差数列求和公式. S=(a1+a1+k-1)k/2=(2·a1+k-1)*k/2;a1是首项,k是个数. 枚举k,首项最小为1,k最大,具体不 ...
- 拓扑排序+DFS(POJ1270)
[日后练手](非解题) 拓扑排序+DFS(POJ1270) #include<stdio.h> #include<iostream> #include<cstdio> ...
- python __builtins__ credits类 (15)
15.'credits', 信用 class _Printer(builtins.object) | interactive prompt objects for printing the licen ...
- bzoj 2064: 分裂【状压dp】
参考:https://www.cnblogs.com/liu-runda/p/6019426.html 有点神奇 大概就是显然最直观的转移是全部合起来再一个一个拆,是n+m次,然后设f[i][j]为分 ...
- Spring boot整合redis实现shiro的分布式session共享
我们知道,shiro是通过SessionManager来管理Session的,而对于Session的操作则是通过SessionDao来实现的,默认的情况下,shiro实现了两种SessionDao,分 ...
- IT兄弟连 JavaWeb教程 重定向
HTTP协议规定了一种重定向机制,重定向的运作流程如下: ● 用户在浏览器端输入特定URL,请求访问服务器端的某个组件. ● 服务器端的组件返回一个状态码为302的响应结果,该响应结果的含义为: ...
- Angular 项目开发中父子组件传参
在项目开发中经常会遇到 组件之间传参的问题.今天总结下在使用angular的项目中父子组件传参的问题: 1.父组件向子组件传参: 然后在父组件中 然后在父组件的html中 然后就可以在子组件中使用了 ...
- TensorFlow多线程输入数据处理框架(二)——输入文件队列
参考书 <TensorFlow:实战Google深度学习框架>(第2版) 一个简单的程序来生成样例数据. #!/usr/bin/env python # -*- coding: UTF-8 ...
- PopupWindow(1)简介
PopupWindow有点类似于Dialog,相同点在于都是弹出窗口,并且都可以对其进行自定义显示,并且里面的监听组件,进行相应的操作,但它与Dialog又有很大的区别,PopupWindow只是弹出 ...