In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the common interview questions in python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. The limitation of multithreading under python and the way to pass parameters in multi-process.
Python multithreading has a global interpreter lock (global interpreter lock), which means that only one thread can use the interpreter at any one time. It means that everyone runs multiple programs with a single cpu. This is called concurrency, not parallelism.
Data can be shared among multiple processes, using multiprocessing.Value and multiprocessing.Array.
2. What is the lambda function? What are the benefits of it?
The lambda function is a function that can take 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 much into the lambda function; if you need something more complex, define a normal function and make it as long as you want.
3. How does Python convert types?
① function description
② int (x [, base]) converts x to an integer
③ long (x [, base]) converts x to a long integer
④ float (x) converts x to a floating point number
⑤ complex (real [, imag]) creates a plural
⑥ str (x) converts object x to a string
⑦ repr (x) converts object x to an expression string
⑧ eval (str) is used to evaluate a valid Python expression in a string and returns an object
⑨ tuple (s) converts sequence s into a tuple
⑩ list (s) converts sequence s into a list
⑪ chr (x) converts an integer to a character
⑫ unichr (x) converts an integer to a Unicode character
⑬ ord (x) converts a character to its integer value
⑭ hex (x) converts an integer to a hexadecimal string
⑮ oct (x) converts an integer to an octal string
4. The difference between python multithreading and multiprocess.
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. Therefore, it is necessary to call the join () method (effectively equivalent to wait) on each Process object. For multithreading, this is not necessary because there is only one process.
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, the above approach is not appropriate because each process has its own independent memory space. At this point, we can share resources by sharing memory and Manager. However, this increases the complexity of the program and reduces the efficiency of the program because of the need for synchronization.
5. How to copy an object in Python?
The copy module in the standard library provides two ways to copy. One method is copy, which returns an object that contains the same content as the parameter. Using the deepcopy method, the properties in the object are also copied.
6. Introduce the usage and function of except?
Python's except is used to catch all exceptions, because each error in Python throws an exception, so each program error is treated as a run-time error.
7. What is the function of the pass statement in Python?
The pass statement does nothing, usually as a placeholder or creating a placeholder, and the pass statement does nothing.
8. The types and characteristics of Python interpreter?
Python is an interpreter language. If the code wants to run, it must be executed through the interpreter. Python has a variety of interpreters, which are developed based on different languages. Each interpreter has different characteristics, but it can run Python code normally. Here are five commonly used Python interpreters:
CPython: when you download and install Python2.7 from the official Python website, you directly get an official version of the interpreter: Cpython, which is developed in C, so it's called CPython. Running python under a named line starts the CPython interpreter. CPython is the most widely used Python interpreter.
IPython:IPython is an interactive interpreter based on CPython, that is to say, IPython is only enhanced in the interactive mode, but the function of executing Python code is exactly the same as CPython, just like many domestic browsers actually call IE although the appearance is different.
PyPy:PyPy is another Python interpreter, its goal is execution speed. PyPy uses JIT technology to dynamically compile Python generation, so it can significantly improve the execution speed of Python code.
Jython:Jython is a Python interpreter running on the Java platform, which can directly compile Python code into Java bytecode for execution.
IronPython:IronPython is similar to Jython, except that IronPython is a Python interpreter running on Microsoft's .net platform that compiles Python code directly into .net bytecode.
In the Python interpreter, the widely used CPython, for the compilation of Python, in addition to using the above interpreter for compilation, skilled developers can also according to their own needs to write Python interpreter to execute Python code, very convenient!
9. List the Boolean value as the common value of False?
0, [], (), {},', False, None
10, string, list, tuple, dictionary each commonly used 5 methods?
String: repleace,strip,split,reverse,upper,lower,join.
List: append,pop,remove,sort,count,index.
Tuple: index,count,__len__ (), _ _ dir__ ()
Dictionary: get,keys,values,pop,popitems,clear,items.
11. Lambda expression format and application scenarios?
Expression format: lambda is followed by one or more parameters, followed by a colon, followed by an expression. There is a parameter before the colon and a return value after the colon. For example: lambda x: 2x
Application scenarios: often used in conjunction with some built-in functions, such as map (), filter (), sorted (), reduce (), etc.
12. What is the role of pass?
① empty statement do nothing
② guarantees format integrity
③ guarantees semantic integrity.
13. Arg and * kwarg function?
The universal parameter solves the problem that the function parameter is not fixed.
* arg: converts the position parameter to tuple
* * kwarg: converts keyword parameters to dict
14. What's the difference between is and =?
Is: determines whether memory addresses are equal
=: judge whether the values are equal.
15. Briefly describe the deep and shallow copies of Python and the application scenarios?
Copy (): shallow copy, shallow copy refers to copying only the first layer of data in the data set
Deepcopy (): deep copy, deep copy refers to all layers of copying the data set
16. Python garbage collection mechanism?
Python adopts two strategies: citation counting mechanism, mark-clear mechanism and generational collection (intergenerational recovery, generational recycling).
Counting mechanism:
Python's GC module mainly uses reference counting to track and collect garbage. On the basis of reference counting, you can also use "Mark-clear"
Resolve the problem of circular references that may be generated by container objects. Through generation-by-generation recycling, space is exchanged for time to further improve the efficiency of garbage collection.
Mark-clear:
The emergence of tag-cleanup breaks circular references, that is, it focuses only on objects that may produce circular references.
Disadvantages: the additional operations caused by this mechanism are proportional to the blocks of memory that need to be reclaimed.
Intergenerational recycling:
Principle: all memory blocks in the system are divided into different sets according to their survival time, and each set becomes a "generation".
The frequency of garbage collection decreases with the increase of the survival time of the generation. In other words, the longer you live, the less likely you are to be rubbish.
We should reduce the frequency of garbage collection. So how to measure this survival time: it is usually measured by several garbage collection actions
The more times an object goes through garbage collection, the longer the object will survive.
17. Mutable and immutable types of python?
Immutable types (numbers, strings, tuples, immutable sets)
Mutable types (lists, dictionaries, variable collections).
18. What is the difference between search () and match () in Python?
The match () function only detects whether the RE matches at the beginning of the string, and search () scans the entire string for a match, that is, match () returns only if the match is successful at position 0, and match () returns none if the start position is not matched successfully.
19. What's the difference when matching HTML tag with Python?
The former is a greedy match, which matches xyz from beginning to end, while the latter is a non-greedy match, which only matches to the first >.
20. How to generate random numbers in Python?
Import random
Random.random ()
It returns a random floating-point number between 0 and 1.
This is the end of the content of "what are the common interview questions in python"? thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.