In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the interview questions that Python engineers need to master". The explanation in the article is simple and clear and easy to learn and understand. please follow the editor's train of thought to study and learn "what are the interview questions that Python engineers need to master"?
1. What are the characteristics and advantages of Python?
A: as an entry-level programming language, Python mainly has the following features and advantages: interpretable, object-oriented, concise, simple and open source with strong community support
2. What is the difference between a deep copy and a shallow copy?
A: deep copy is copying one object to another, which means that if you make a change to a copy of an object, it will not affect the original object. In Python, we use the function deepcopy () to perform a deep copy and import the module copy as follows: > import copy > b=copy.deepcopy (a) while a shallow copy copies a reference from one object to another, so if we change it in the copy, it will affect the original object. We use the function function () to perform a shallow copy, using the following: > b=copy.copy (a)
3. What is the difference between lists and tuples?
A: the main difference between the two is that lists are mutable and tuples are immutable. For example, it is shown as follows: > mylist= [1mai 3je 3] > mylist [1] = 2 > > mytuple= (1mc3) > mytuple [1] = 2 Traceback (most recent call last): File ", line 1, in mytuple [1] = 2 will have the following error: TypeError: 'tuple' object does not support item assignment
4. How to implement multithreading in Python?
A: a thread is a lightweight process, and multithreading allows us to execute multiple threads at a time. As we all know, Python is a multithreaded language with a built-in multithreaded toolkit. The GIL (global interpreter lock) in Python ensures that a single thread is executed at a time. One thread saves the GIL and performs some operations before passing it to the next thread, which gives us the illusion of running in parallel. But in fact, it's just threads running in turn on the CPU, and of course, all the passes add to the memory pressure on the program's execution.
5. Explain inheritance in Python
A: when a class inherits from another class, it is called a subclass / derived class, inherited from the parent class / base class / superclass. It inherits / gets all class members (properties and methods). Inheritance allows us to reuse code and make it easier to create and maintain applications. Python supports the following kinds of inheritance: single inheritance: a class inherits from a single base class: a class inherits from multiple base classes at multiple levels: one class inherits from a single base class, and the latter inherits hierarchically from another base class: multiple classes inherit from a single base class mixed inheritance: a mixture of two or more types.
6. what is a monkey patch?
Dynamically modify a class or module during operation. > class A: def func (self): print ("Hi") > def monkey (self): print "Hi, monkey" > m.A.func = monkey > a = m.A () > > a.func () the running result is: Hi, Monkey
7. Please explain the meaning of using * args and * kwargs
In python, * args and * * kwargs are usually used in function definitions. Both * args and * * kwargs allow you to pass an indefinite number of arguments to a function, even if you don't know how many arguments the caller will pass when defining the function. Ps: * args and * * kwargs are just a habit that everyone follows, and their names can be written at will. 1. * args example * args can receive indefinite non-keyword parameters and convert position parameters into tuple (parameter groups of non-key-value pairs). The example is shown in the following code: def func (* args): for i in args: print (I) func (1m 2m 3J 4) results: 1234 2.**kwargs example * * kwargs allows you to pass non-quantitative keyword parameters. If you need to define an indefinite number of named parameters in a function, then you need to use * * kwargs, which converts keyword parameters into dict (key-value pair argument groups). The example is shown in the following code: def func (* * kwargs): for i in kwargs: print (iQuery Kwargs [I]) func (axi1Leo baked 2MIT 3Md 4) run result: a 1b 2c 3d 4
8. What is the difference between new and init in python?
_ _ new__ is a static method and _ _ init__ is an instance method. The _ _ new__ method returns a created instance, while _ _ init__ returns nothing. The following _ _ init__ can be called only if _ _ new__ returns an instance of cls. Use _ _ init__. when initializing an instance by calling _ _ new__, when creating a new instance
9. Explain the ternary operation in Python
Unlike Python, we don't have?: in Python, but we do have this: [on true] if [expression] else [on false] if the expression is True, execute the statement in [on true]. Otherwise, execute the statement in [on false]. Here are the ways to use it: > min=an if a > > min running result: 2 > print ("Hi") if a
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.