Python tutorial: the most comprehensive Python110 pavement questions! There's an interview you need them

Python tutorial: Complete 110 Python face questions!

To everyone better digestion, to everyone out here is divided into several topics and tutorials!


1, the sum of a line of code to achieve 1--100

Using the sum () function sums


2, how to modify global variables inside a function

Internal functions global declaration modify global variables


3 , lists five python standard library

os: provides functions related to the operating system with a lot of

sys: command-line arguments commonly used

re: regular match

math: math

datetime: date and time of treatment

4, how to merge two dictionaries and dictionaries delete key

del and update methods


5, under the python's GIL talk

GIL Global is the python interpreter lock, the same process if there are multiple threads running, a thread when running python program will occupy the python interpreter (ie had a lock GIL), the other threads within that process can not run, and so the thread running after other threads to run. If the process thread running encountered time-consuming operation, the interpreter unlock the lock, so that other threads to run. So in multiple threads, the thread is still running is a sequential, not simultaneous.

Run multiple processes at the same time in each process can be allocated as system resources, equivalent to each process has a python interpreter, it can achieve multi-process multiple processes, the big disadvantage is that the process of system resource overhead

6, python list of methods to achieve weight

First go through a set of heavy, in turn list


7, fun (* args, ** kwargs) of * args, ** kwargs What does it mean?



Distinction 8, python2 python3 and a range (100) of

python2 return to the list, python3 returns an iterator, save memory

9, in a word to explain what kind of language can be used decorator?

As a function of transmission parameters of the language, you can decorator

10, python built-in data types which

Integer --int

Boolean --bool

String --str

--List list

Tuple --tuple

Dictionary --dict

11, the object-oriented briefly and __init__ difference __new__

__init__ is the initialization method, after creating an object, it was immediately called by default, and can receive parameters, as


1, __ new__ CLS have at least one parameter, representative of the current class, this parameter is automatically recognized by the Python interpreter at instantiation

2, __ new__ must have a return value, return to instantiate an instance of it, and this point in time to achieve their own __new__ pay special attention to, can return the parent class (via super (current class name, cls)) __ new__ out examples , or directly out of the object of example __new__

3, __ init__ parameter has a self, is an example of the return __new__, __ init__ can do some other initialization operations on the basis __new__, __ init__ no return value

4, if __new__ creating an instance of the current class, will automatically call the __init__ function, the first argument of the function called by __new__ return statement inside cls to ensure that the current class instance, if other classes class name; then the actual return is to create instances of other classes, in fact, does not call the __init__ function of the current class, nor does it call other class __init__ function.


12, briefly with ways to open the file to help me deal with what we do?


Open the file during read and write when there may be some abnormal condition, according to conventional f.open

Written, we need to try, except, finally, do the abnormality judgment, and the final document no matter what the situation, we must execute finally f.close () closes the file, with ways to help us achieve finally the f.close

(Of course, there are other custom features, are interested can study method with source code)

13 , the list [1,2,3,4,5], using the map () function output [1,4,9,16,25], and the formula used to derive a list number greater than 10 is extracted, the final output [16 , 25]

map () function is the first parameter fun, the second parameter is typically List, the third parameter List can be written, can not write, according to the needs


14, python random integer generated randomly decimal, fractional method between 0--1

Random integer: random.randint (a, b), generating an integer in the interval

Random decimal: accustomed numpy library using np.random.randn (5) generates a random decimal 5

0-1 random decimal: random.random (), does not pass parameters in parentheses


15, to avoid the escape string plus what letter represents the original string?

r, expressed the need for the original string, does not escape special characters


Reproduced in: https: //juejin.im/post/5cf7622351882544d33b9612

Guess you like

Origin blog.csdn.net/weixin_34126557/article/details/91469864