In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the Python interview questions and answers". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the Python interview questions and answers.
The first question, what is the difference between = and is?
= = values are compared, and is compares values and references (object memory space)
For example:
> > a = 123 > > b = 123 > > a = = bTrue > > an is bTrue > id (a) 9670848 > id (b) 9670848
As long as it is an immutable type variable (numeric, string), as long as the value is the same, the object memory space is the same.
Is and = = of variable type variables
> c = [1Jing 2jue 3] > > d = [1JI 2jue 3] > c = = dTrue > > c is bFalse > id (c) 140470599331072 > id (d) 140470599331200
For variable types, the memory space of each variable is different.
Second, members' understanding of single underscore _ foo and double underscore _ _ foo and _ _ foo__ in Python
1. _ foo cannot be directly used for 'from module import *'
2. The _ _ foo parser replaces the name with _ classname__foo to distinguish it from the same name as other classes
3. _ _ foo__ represents the logo specific to special methods in python.
Question 3, what is the difference between _ _ new__ and _ _ init__?
1. _ _ new__ is a static method, and _ _ init__ is an instance method
2. The _ _ new__ method returns a created instance, while _ _ init__ returns nothing
3. Only when _ _ new__ returns an instance of cls can the following _ _ init__ be called.
4. Use _ _ init__ when initializing an instance by calling _ _ new__, when creating a new instance
Question 4, the role of sinstance and issubclass?
1. Sinstance (object,classinfo), which is used to determine whether object is an instance of classinfo, or whether object is an instance of a subclass of the classinfo class, and returns True.
2. Issubclass (class,classinfo), which is used to determine whether class is a subclass of the classinfo class, and if True is returned.
Question 5, the following statements of Python2 and Python3 are correct (ABC)
A, Python3 using print must wrap the printed content in parentheses
Ascii coding is used in B, Python2, and utf-8 coding is used in Python3.
In C and Python2 is the raw_input () function, and in Python3 is the input () function
Range in D, Python2 (1pm 10) returns a list, and iterator in Python3
D answer, return a list in python2, return a range type in python3, not an iterator
Question 6. How to understand the GIL of python?
First of all, it needs to be clear that GIL is not a feature of Python, it is a concept introduced in the implementation of Python parser (CPython).
Why with GIL, in order to take advantage of multi-core, Python began to support multi-threading. Naturally, the easiest way to solve the problem of data integrity and state synchronization between multithreads is to add locks. As a result, GIL is a super big lock, and as more and more code base developers accept this setting, they begin to rely heavily on this feature (that is, the default python internal object is thread-safe, without having to consider additional memory locks and synchronization operations in the implementation.
The whole process of GIL is Global Interpreter Lock, which means global interpreter lock.
In CPython, the mainstream implementation of the Python language, GIL is a genuine global thread lock, which needs to be acquired when the interpreter interprets and executes any Python code, and will be released when it encounters an Python O operation. If it is a pure computing program, without the Icano operation, the interpreter will release the lock every 100 operations, giving other threads a chance to execute it, which can be done through sys.setcheckinterval. If you don't release the lock, other programs will be waiting.
Question 7, briefly describe the with method to open the processing file to help us do what?
Some abnormal conditions may occur when opening a file for reading and writing. If we follow the conventional file.open writing method, we need try,except,finally to make an exception judgment, and no matter what happens to the file, we have to execute file.close () of finally to close the file.
The with method helps us implement the file.close () operation in finally, as follows
Question 8. Avoid escaping which letter to add to the string to represent the original string
R, indicating that the original string is required and special characters are not escaped
Question 9, examples of Python interruption methods.
Assert () method, if the assertion is successful, the program continues to execute; if the assertion fails, the program reports an error
Question 10, how to convert a list type to an iterator
> a = [1 iter (a) > next (a) > a = [1pia 2 pyrrine 3 pyrrine 4 pyrrine 5 pyrrine 6] > a = a. Accountabilityexamiteriterator _ () > a.sancnextaccount1 to this point, I believe you all have a deeper understanding of "Python interview questions and answers". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.