Python Interview Key (Basics)
Will answer the first part (2 points)
Brief list of differences between the programming language and understand the language?
python easy to learn interpreted relative to the
high cost of java blended learning, doing java Web
c compiled underlying language
added to the base type c c ++ compiler on object-oriented
go compiled high concurrency, Block Chaining语言特点: 灵活简洁,语言优美 可读性强, 语言类型: 解释型:逐行转化,运行效率低,性能差,开发效率高。兼容性好,跨平台 编译型 :一次性编译成二进制文件,执行效率高,兼容性差, 动态语言:不用声明变量的数据类型(脚本类语言) 静态语言:需要声明变量的数据类型 第三方库:python定位是任其发展,开源库很多,应用领域广
List of differences Python2 and Python3?
Python 2 only supports the year 2020
Print function without parentheses Python3 Python2 bracketed statement becomes a function of the
input Python2 user input as a function of type int, raw_input to a string to a string Python3
/ 2 The obtained result divisor divisible decimal places , 3 Zhenchu shaping
default encoding is ascll 2 3 utf-8 code
range! = <> Python3 canceled <>
int Type 2 Type 3 only have long int
Range 2 is a listing xrange iterables 3 is iterables
2 new classes, new classes Classic 3Look at the code written results
v1 = 1 or 2 #v1 = 1 v2 = 3 and 7 or 9 and 0 #v2 = 7 or 0 #v2 = 7 在没有()的情况下not 优先级高于 and,and优先级高于or x or y , x为真,值就是x,x为假,值是y; x and y, x为真,值是y,x为假,值是x。 两边都不是0的情况下 and 直接取后面的值 or 直接取前面的值 如果存在0的情况 and 直接取0 or 直接取非0 false是 0 。。
- Compare the following values What is the difference?
= V1 [l, 2,3]
V2 = [(. 1), (2), (. 3)]
V3 = [(. 1,), (2,), (. 3,)]
. 1 and 2, no great difference, 3, then (1) is represented by a tuple (1) which represents the type of element itself Value exchange achieved by line of code.
. 1 = A
B = 2#a,b = b,a
- Python single difference between double quotation marks, the three quotes?
python, each may comprise single and double quotation marks, to avoid escape,
and the three marks has two effects wrap long strings, and comments the difference is and ==?
Three basic objects: type (data type) id (identity) and value (value)
if value == compare two objects are equal
is determined whether or not the same value idhow to achieve transformation in python tuple and list of?
tuple (list) # may be added by cyclic
list (tuple) #tuple not be changed, can not be recycled addedHow to achieve a string name = 'old boy' of the reverse?
1. Slice
name = name [:: -. 1]
2. Reverse method list
name = List (name)
name.reverse ()
name = '' .join (name)
to the #NAME = '' .join (name [:: -1])
3.for cycle
# various sections can insert
4.reduce function
NEW_NAME = the reduce (the lambda X, Y: X + Y, name)
Print (NEW_NAME)
5. The recursive
DEF FUNC (S):
IF len ( S) <. 1:
return S
return FUNC (S [. 1:]) + S [0]
6. The use of stack
S = "Hello"
L = List (S)
Result = ""
the while (len (L)> 0):
+ = l.pop Result ()
Print (Result)How to get two set intersection, union, difference?
Intersection List (SET (A) .intersection (SET (B)))
&
union List (SET (A) .union (SET (B)))
|
difference set list (set (b) .difference ( set (a) ))
-- In those cases, y = x -! (Xy ) will be set up?
The X-, the y-two is not equal non-empty set How to copy an object in Python?
In order not to change the original data is data generated when modifying a copy of
the copy module copy.copy () copy.deepcopy ()
[:]
variable object: the so-called variable refers to a variable object a variable value, identity (id) is Changeless. Such as: lists, dictionaries, a set of
immutable objects: the identity and value of the object is not variable. Such as: Digital (figure is immutable, remember), strings, tuplesDescription of the assignment, a shallow copy and deep copy of the difference?
Principle separated data, modify the data independently of each other赋值:让多个变量同时指向一个对象的内存地址。不可变对象在赋值时会开辟新空间。可变对象在赋值时,修改一个的值,另一个也会发生改变。 浅拷贝:(copy模块的copy.copy()函数) 拷贝父对象,不会拷贝对象的内部的子对象。不可变对象和赋值没区别。可变对象,浅拷贝在拷贝时,只拷贝第一层中的引用,如果元素是可变对象,并且被修改,那么拷贝的对象也会发生变化。####拷贝第一层元素内存地址 深拷贝:完全拷贝了父对象及其子对象。深拷贝就是将顶级对象以及子对象的值同时复制给新对象,此时修改任何一个都不会影响另一个。{copy模块的 copy.deepcopy()函数}####不管多少层,不可变共有,可变开辟新空间 但由于小数据池的概念,python中 -5~~256 20字符串 bool完全共享内存地址
- pass effect?
Footprint
... Write result of reading the code.
Copy Import
A = [1,2,4,5, [ 'B', 'C']]
B = A
C = copy.copy (A)
D = copy.deepcopy (A)a.append(5) a[4].append('d') print(b) print(c) print(a)
Achieve 9 * 9 multiplication tables with Python.
Python and display a Fibonacci number.
= LST [1,1]
for I in Range (10):
lst.append ()How do I delete the list of duplicate values?
list (set (list))A file size of 100G etl_log.txt, to read the contents of the file, write the specific procedure code?
for i in the file handlea = dict (zip (( " a", "b", "c", "d", "e"), (1,2,3,4,5))) to ask a what?
The way to create a dictionarythe role of lambda keyword?
Define an anonymous function* arg and kwarg role?
* arg position to accept the extra parameters
kwarg accepts excess keyword argumentsHow to set a global variable in a function?
, Ltd. Free Join namefilter, map, reduce role?
filtration filter
map mappings
reduce accumulated calculatedWhat is the anonymous function? Anonymous function What is the role?
lambda function is an anonymous function, a function of a word
with the higher-order functions using
higher-order functions: write methodThe maximum number of layers Python recursion?
Official 1000 actual 994-998
Import SYS
sys.setrecursionlimit (10000) amend the maximum depth of recursionWhat is an iterator? What is iterables?
Has __iter __ () and __next __ () method is iterator
has __iter __ () method is iterable
all properties and methods .dir () to view an objectWhat is a generator? What is a decorator and application scenarios?
Essence generator iterators with yield is the keyword generator
decorator nature closure, without modifying the source code and call mode, additional functions
login authentication
type
the Flask
DjangoWhat is the reflection and application scenarios?
By the methods and properties of the string operation target
application scenarios:
a user input selection is determined, CBVWrite a general decorator.
Write a decorator with arguments.
求结果
def num():
return [lambda x:i*x for i in range(4)]
print([m(2) for m in num()])[6,6,6,6]
def (a, b = [] ) The wording What trap?
The default data type parameter is a variable closureSee results code written
DEF FUNC (A, B = []):
b.append (A)
return Bv1 = func(1) v2 = func(2,[10,20]) v3 = func(3) print(v1,v2,v3)
See results code written
DEF FUNC (A, B = []):
b.append (A)
return Bv1 = func(1) print(v1) 1 v2 = func(2,[10,20]) print(v2) 10 20 2 v3 = func(3) print(v3) 1 3
Please write a function to achieve - replaced by an integer.
The conversion rule is 10.3.9.12:
10 00001010
. 3 00000011
. 9 00001001
12 is 00001100再将以上二进制拼接起来计算十进制结果:00001010 00000011 00001001 00001100 = ?
Please find all the files under a directory (there may file nested).
os.walk () recursive natureSeeking results
Import the Math
Print (Math.floor (5.5))
floor in addition to 5Whether used in a function functools? what is the function?
reduce wrapsThe difference between re search and match?
match from the beginning of the match, a match is stopped
search for a match from an arbitrary position matching is stoppedWhen matched with Python HTML tag, the < > and <?> What is the difference?
. Greedy match to match any number of characters
. *? Non-greedy match only onceHow to generate a random number?
Random
random.random ()super role?
Inheriting the order of mroThe difference between single and double underline underline?
__a = 10 forcibly private
_b = 15 prescriptive programmer which is a private methodThe difference @staticmethod and @classmethod?
A static method is an ordinary function
a class method isImplementing a singleton pattern (locking).
Multithreading is no longer a single case, in order to ensure it is lockedThe difference between stacks and queues?
After the stack advanced
queue FIFOThe following code outputs are what? Please answer and explanation.
the Parent class (Object):
X =. 1class Child1(Parent): pass class Child2(Parent): pass print Parent.x, Child1.x, Child2.x Child1.x = 2 print Parent.x, Child1.x, Child2.x Parent.x = 3 print Parent.x, Child1.x, Child2.x
Reference to the following code snippet
class the Context:
Passwith Content() as ctx: ctx.do_something() 请在Context类下添加代码完成该类的实现
The second portion may be the topic
- How to get a list of the second largest value?
- Brief Python memory management mechanism.
- Brief Python's garbage collection mechanism.
- Please come to implement a stack using two queues.
- Please use Python to implement a linked list.
- Please reverse the Python implementation of the list.