Reference Pages: Essential Python interview Questions
1. What is Python?
Can be compared with other techniques in the answer (encouraged); If you are applying for a Python development post, you should know what language it is and why it is so cool and where it is not good.
Reference Answer:
- Python is an interpreted language. This means that unlike C and C's derived languages, Python code does not need to be compiled before it can run. Other explanatory languages include PHP and Ruby.
- Python is a dynamic type language, meaning that you do not need to describe the type of a variable when declaring it. You can write similar
x=111 and x="I‘m a string" such code directly, the program will not error.
- Python is ideal for object-oriented programming (OOP) because it supports the definition of classes (class) by combining (composition) and Inheritance (inheritance). There is no access specifier in Python (access specifier, like in C + +
public private ), so the design is based on "everyone is an adult."
- In the Python language, a function is the first class of objects (first-class objects). This means that they can be assigned to a variable, and the function can either return the function type or accept the function as input. Class is also the first class of objects.
- Python code is written fast, but runs slower than the compiled language. Fortunately, Python allows for the inclusion of extensions written in C language, so we can optimize the code to eliminate bottlenecks, which is usually achievable.
numpyis a good example of how fast it works, because many arithmetic operations are not actually implemented by Python.
- Python is very versatile-Web applications, automation, scientific modeling, big data applications, and more. It is also often used as a "glue language" to help other languages and components improve health.
- Python makes difficult things easier, so programmers can focus on the design of algorithms and data structures without having to deal with the underlying details
2. Supplemental missing code: definition of function
Print_directory_contents(spath): "" " This function takes the name of the folder as an input parameter and returns the path to the file in that folder. and the path to the file in the containing folder. # Supplemental Code
Note the point:
- The naming convention should be unified. If you can see the naming convention in the sample code, follow its existing specifications.
- Recursive functions require recursion to terminate. Make sure you understand the principle, or you will face the endless call stack (callstack).
- We use
os modules to interact with the operating system while interacting in a way that can be cross-platform. You can write the code sChildPath = sPath + ‘/‘ + sChild , but this will make an error on the Windows system.
- It is very valuable to be familiar with the basic module, but don't try to memorize it, remember that Google is your mentor at work.
- If you don't understand the expected functionality of the code, ask it boldly.
- Stick to the KISS principle! Keep it simple, but your mind will understand!
Grass Test Answer:
DefPrint_directory_contents(spath):ImportOsForSchildInchOs.listdir (spath): schildpath = os. Path. Join (spath,schild) if os. Path. Isdir (schildpath): print_directory_contents< Span class= "P" > (schildpath) else: print schildpath
3. list problem:
/span>
Read the following code to write the final value of A0,A1 to an
A0 = Dict (Zip (' A ',' B ',' C ',' d ',' E '), (1,2,3,4,5)))
A1 = Range (10)
A2 = sorted ([I for i in A1 if I in A0])
A3 = sorted ([A0[s] for s in A0])
A4 = [i- i in A1 if I in A3]
A5 = {I:i*i for i in A1}
A6 = [[I,i*i] for i in A1]
Reference results:
< Span class= "ow" > < span class= "n" > < Span class= "p" >
Python face question finishing 1