New York Finance Job Interview Training and Guidance: 15 Frequent Python Interview Questions

publish:2022-11-24 16:40:39   views :495
publish:2022-11-24 16:40:39  
495

1. How do I manage memory in Python?

Memory management in Python is managed by Python private heap space. The object and data structure are located in the private heap, and the developer has no right to access the private heap, which is handled by the Python interpreter. The heap space allocation of Python objects is completed by the memory manager. The core API provides some tools for developers to write code. Python's built-in garbage collector recycles all unused memory, making it suitable for heap space.

2. Explain the Help() function and Dir() function in Python.

The Help() function is a built-in function, which is used to view functions and specify module usage.

p1.png 

*Image source network

The running result is:

p2.png 

*Image source network

Dir() function is a Python built-in function. When Dir() function does not take parameters, it returns the list of variables, methods and defined types in the current range; When there are parameters, the list of properties and methods of the parameter is returned.

Give an example to show how to use it:

p3.png

*Image source network

The running result is:

p4.png

*Image source network

3. When Python exits, will all allocated memory be cleared?

The answer is no. When Python exits, Python modules with circular references to other objects and objects referenced from the global namespace will not be deallocated or released. Unable to deallocate those parts of memory reserved by the C library. When exiting, Python will attempt to deallocate/destroy all other objects due to its own efficient cleaning mechanism.

4. What is a monkey patch?

Dynamically modify a class or module during runtime.

p5.png

*Image source network

The running result is:

p6.png 

*Image source network

5. What is a dictionary in Python?

Dictionaries refer to built-in data types in Python. It defines a one-to-one relationship between keys and values, including a pair of keys and their corresponding values. The dictionary is indexed by a key.

6. Explain the logical operators in Python.

There are three logical operators in Python: and, or, not.

7. Why not suggest an underscore as the beginning of an identifier?

Python has no concept of private variable, so it is agreed to declare a variable as private by starting with a quick underscore. Do not start with an underscore if you do not want the variable to be private.

8. What is Flask?

Flask is a lightweight Web application framework written in Python. The WSGI toolkit uses Werkzeug, and the template engine uses Jinja2. Flask uses BSD authorization. Werkzeug and Jinja2 are two environment dependencies. Flask does not need to rely on external libraries.

9. Explain the join () and split () functions in Python.

Join() can be used to add specified characters to the string.

p7.png 

*Image source network

The running result is:

p8.png 

*Image source network

Split() can be used to specify character splitting strings.

p9.png

*Image source network

The running result is:

p10.png 

*Image source network

10. How long is the identifier in Python?

The identifier can be of any length. The following rules must also be observed when naming identifiers:

L Can only begin with an underscore or a letter in A-Z/a-z

L The rest can use A-Z/a-z/0-9

L Case sensitive

L Keyword cannot be used as identifier

11. Is indenting required in Python?

need. Python specifies a code block. All codes in loops, classes, functions, etc. are specified in indented blocks. This is usually done using four space characters. If the developer's code is not indented, Python will not execute accurately and will also throw an error.

12. Please explain the meaning of using * args.

When we don't know how many parameters to pass to the function, such as a list or tuple, we use * args.

 p11.png

*Image source network

The running result is:

p12.png

 

*Image source network

13. What is the difference between a deep copy and a shallow copy?

Shallow copy is to copy the reference of an object to another object. If changes are made in the copy, the original object will be affected. Deep copy is to copy an object to another object. If you change the copy of an object, the original object will not be affected.

14. How to implement multithreading in Python?

Python is a multithreading language with a built-in multithreading toolkit. Multithreading allows us to execute multiple threads at once. The GIL (global interpreter lock) in Python ensures that a single thread is executed at once. A thread saves GIL and performs some operations before passing it to the next thread, which looks like the illusion of parallel operation. In fact, threads run on the CPU in turn. All transfers will increase the memory pressure of program execution.

15. What are closures in Python?

When a nested function references a value in its outer region, the nested function is a closure. This means that this value will be recorded.

For example:

p13.png 

*Image source network

The running result is:

p14.png   *Image source network

the
-
Service and products
Unlimited internal referrals for full-time jobs
Overseas internship admission
Interview training for famous enterprises
Refinement of workplace documents
OPT/CPT application
Graduation Guarantee program
Unlimited internal referrals for full-time jobs
Domestic internship admission
Interview training for famous enterprises
Refinement of workplace documents
Graduation Guarantee program
One-to-one remote PTA
Group remote PTA
Domestic field training
Overseas Field Training
Background Skills Training Course
Contact us
0571-87823776
joy@career-infinite.cn
US Headquarters:1000 Massachusetts Ave,Boston, MA 02118
UK Headquarters:10 York Rd, South Bank, London SE1 7ND
China Headquarters:30/F, Jiarun Mingzuo, Jinji Road, Xiaoshan District, Hangzhou City, Zhejiang Province, China(浙江省杭州市萧山区金鸡路嘉润铭座30F)
Scan the code and reply [gift]
To receive a $299 overseas job hunting gift
copyright© 2016-2022 浙江升涯教育科技有限公司. All rights reserved 寰球贸易SEO.升涯求职.
Powered by Feedback Manage