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 ...
随机推荐
- application、session、request、page的作用范围、Application,Session和Cookie的区别
Web应用中的JSP和servlet都是由web服务器来调用,Jsp和Servlet之间通常不会相互调用,那么Jsp和Servlet之间交换数据就要用到application.session.requ ...
- bzoj 5499: [2019省队联测]春节十二响【堆】
首先看两条链怎么合并,贪心可得是从大到小取max,多条链同理 所以dfs合并子树的大根堆即可,注意为了保证复杂度,合并的时候要合并到最长链上,证明见长链剖分 #include<iostream& ...
- MySQL 错误码对照
1005:创建表失败 1006:创建数据库失败 1007:数据库已存在,创建数据库失败 1008:数据库不存在,删除数据库失败 1009:不能删除数据库文件导致删除数据库失败 1010:不能删除数据目 ...
- Mac 开发 Hue
1)环境准备 Maven 3.6.1 python (Anaconda 2.7.16) MySQL 5.7 git 2.21 2)Hue源码下载 git clone git@github.com:ar ...
- 1.基础数据类型的初识 字符串 bool 整型 if else elif
---恢复内容开始--- 计算器基础知识 cpu :人类的大脑 运算和处理问题 内存:临时存储数据 断点就消失了 高铁 硬盘:永久存储数据 图片 操作系统:是一个软件 控制每个硬件之间的数据交互 Py ...
- NOIp 2015信息传递【tarjan/拓扑/并查集】
一道好的NOIp题目,在赛场上总能用许多算法A掉.比如这道和关押罪犯. 题目传送门 法一:tarjan在有向图中跑最小环 有人从别人口中得知自己信息,等效于出现了一个环.于是 这就变成了一个有向图ta ...
- 在MacOs上安装sqlsrv Mojave - 找不到'php.h'文件
Mojave没有安装标头. 要安装标头: open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_1 ...
- 1-16使用try-catch捕捉异常
处理异常 可以使用try-catch-处理异常,例如之前的程序可以使用try-catch-处理 package com.monkey1024.exception; import java.io.Fil ...
- Linux 命令与学习
2014-10-10 ps -ef|grep *** 可以查找包含***名称的进程 netstat -ntlp 查看端口占用 kill -9 pid 强制杀死进程 ...
- Reference for shell scripting
${var} 和 $var的区别 http://stackoverflow.com/questions/8748831/when-do-we-need-curly-braces-in-variable ...