Python programming interview questions: parameter passing method and lambada function

Python programming interview questions: parameter passing method and lambada function

[Guide] In the process of Python programming interview, there will be professional investigations. The parameter transfer method, lambada function, etc. are the key points. Therefore, if the interview is successful, we need to prepare in advance and do more Python programming. Interview questions, today I bring you Python programming interview questions: parameter passing method and lambada function, hurry up and see the answer.

Python programming interview question 1: the limitations of multithreading under python, the way of passing parameters and the difference

(1) The limitation of multi-threading under python and the way of passing parameters in multi-process

Python multithreading has a global interpreter lock. This lock means that only one thread can use the interpreter at any time. It means that multiple programs run with a single CPU. Everyone uses it in turn. It's called "concurrency", not "parallel".

To share data between multiple processes, you can use multiprocessing.Value and multiprocessing.Array

(2) The difference between python multithreading and multiprocessing

On the UNIX platform, when a process terminates, the process needs to be called wait by its parent process, otherwise the process becomes a zombie process (Zombie). Therefore, it is necessary to call the join() method on each Process object (actually equivalent to wait). For multithreading, since there is only one process, there is no such necessity.

Multiple processes should avoid sharing resources. In multithreading, we can easily share resources, such as using global variables or passing parameters. In the case of multiple processes, since each process has its own independent memory space, the above method is not appropriate. At this point, we can share resources by sharing memory and Manager. But doing so increases the complexity of the program and reduces the efficiency of the program because of the need for synchronization.

Python programming interview question 2: lambada function

A lambda function is a function that can receive any number of parameters (including optional parameters) and return a single expression value. Lambda functions cannot contain commands, and they cannot contain more than one expression. Don't try to cram too many things into the lambda function; if you need something more complex, you should define a normal function and make it as long as you want.

The above is the Python programming interview questions: the sharing of parameter transfer methods and lambada functions. I hope you can answer these questions well during the interview, and try to pass the Python programming interview and get the offer of the corresponding position. I wish you success !

Guess you like

Origin blog.csdn.net/qq_38397646/article/details/110421975