Python interview FAQs


What is Python?

It can be compared with other languages in the answer. firstPythonIt’s an interpretive language. AndCLanguage andCPython code does not need to be compiled before it runs. Other interpretative languages includePHPandRubyPythonIt is also a dynamically typed language, which means that you do not need to specify the type of a variable when you declare it.PythonIt is very suitable for object-oriented programming, because it supports defining classes through composition and inheritance. stayPythonEverything in the world is the object.

After answering the characteristics of python, we can talk about the advantages and disadvantages of Python.

PythonThe code is fast, although the running speed is usually slower than the compiled language, butPythonAllow to join based onCLanguage, so we can optimize the code and eliminate bottlenecks,numpyThis is a good example. Python is widely used, not limited to network applications, automation, scientific modeling, big data applications and so on. It is also often used as a “glue language” to help other languages and components improve their performance. At the same time, python makes difficult things easy, so programmers can focus on the design of algorithms and data structures without dealing with the underlying details.

We need to understand why the interviewer asked this question: if you are applying for a jobPythonAs a developer, you should know what kind of language it is and why it’s so cool. And what’s wrong with it.

What is pep8?

PEP8Is a programming specification, content is about how to make your program more readable suggestions.

What are pickling and unpicking?

PickleModule reads anyPythonObject, convert them to strings, and then use thedumpFunction to dump it into a file. This process is calledpickling

Instead, extract the original string from the stored string filePythonObject is called unpicking.

How is Python interpreted?

PythonIs an explanatory language, its source code can be run directly.PythonThe interpreter converts the source code into an intermediate language and then translates it into machine code for execution.

How does Python manage memory?

PythonThe memory management of is by privateheapSpace management is very important. be-allPythonObjects and data structures are in the same private domainheapIn the middle. The programmer did not access the fileheapOnly the interpreter can operate on it. byPythonOfheapSpace allocation memory is made up ofPythonIts core API will provide some methods to access the module for programmers to use.PythonThere is a built-in garbage collection system, which recycles and releases unused memory so that it can be used by other programs.

What tools can help debug or do static analysis?

PyCheckerIs a static analysis tool, it can not only report errors in source code, but also report error type and complexity. Pylint is another tool to check whether a module meets the code standard.

What’s the difference between arrays and tuples?

The difference between arrays and tuples: the contents of arrays can be modified, while the contents of tuples are read-only. In addition, tuples can

Hashed, such as a keyword in a dictionary.

How to implement parameter passing by value and reference?

PythonEverything in is a class, and all variables are references to an object. The value of the reference is determined by the function because

This cannot be changed. But if an object can be modified, you can change it.

What is the python namespace?

stayPythonIn, all names exist in a space, and they exist and are manipulated in that space

Namespace. It is like a box, each variable name corresponds to an object. When querying variables, the corresponding objects will be found from the box.

What is a lambda in Python? Why lambdaNo statements?

This is an anonymous function that is often used for a single expression in code. Anonymous functionlambdaThe reason there is no statement is that it is used to build a new function object and return it when the code is executed.

What is pass in Python?

PassIt’s a place wherePythonStatements that will not be executed in. In complex statements, if a place needs to be left blank temporarily, it is often used as a place holder.

What is docstring in Python?

PythoChinese file strings are calleddocstringIt’s inPythonThe role of is to generate documentation for function, module, and class annotations.

How to copy an object in Python( Assignment, shallow copy, deep copy)

Assignment (=) creates a new reference to an object. Modifying any of the variables will affect the other.

Shallow copy: create a new object, but it contains a reference to the item contained in the original object (if by reference)

If one of the objects is modified, the other will be modified as well.)

Deep copy: create a new object, and recursively copy the objects it contains (modify one, and the other does not)

(it will change)

The difference between single quotation mark, double quotation mark and triple quotation mark

Single quotation marks and double quotation marks are equivalent. If you want to wrap a line, you need the symbol (\), and three quotation marks can wrap a line directly and can contain comments

This work adoptsCC agreementReprint must indicate the author and the link of this article