Python pen question (ii)

Source: Internet
Author: User
Tags generator shallow copy

1. What is Gil? Gil full name Global interpreter lock, essentially a mutex, is not a Python feature. The limitations of the standalone thread that Python takes to ensure thread safety is that a kernel can only run a thread at the same time. Python multithreading works for IO-intensive tasks, but Python's multithreading is almost no advantage for CPU-intensive tasks. It is also possible to slow down because of contention for resources. 2What is the difference between Staticmethod and Classmethod in Python? Difference: Call method Different static method: Called by class, no default parameter class method: Called by the class, at least one CLS parameter, when the class method is executed, the class that calls the method is automatically copied to self3How to copy an object in Python and explain the depth copy you can generally use the copy.copy () method or the Copy.deepcopy () method to shallow copy: Create a new object, but it contains a reference to the containing item in the original object ( If one of the objects is modified by reference, the other one is also changed) deep copy: Create a new object and recursively copy the objects it contains (modify one, and the other will not change)4The difference between search () and match () in Python contains match (pattern,string) in the RE module, checks if the beginning of the string matches pattern, returns a matching object, and returns none if not found Re module search (pattern,string), searching for the first matching value in string, if not found, returns none5What is the difference between iterators and generators and their differences? Builder: A generator is a special function that generates a value at a time, and in the process of executing the function, the yield statement returns the value you need to the calling generator, exits the function, executes the next time the generator function is called, and the variable parameter in the generator is saved for    Secondary use. Iterators: Any object that implements the __iter__ and __next__ methods is an iterator. __iter__ Returns the iterator itself,__next__ returns the next value in the container. The generator is a special iterator that internally has both of these methods6What is a co-process?    How is the Python process implemented? The process is a kind of user-state lightweight thread, the scheduling of the process is entirely user-controlled. The process has its own register context and stack, when the co-scheduling switch, the register context and the stack is saved to other places, the back of the recovery of the previously saved context and stack, the direct operation of the stack and basically no kernel switching overhead, can be unlocked access to global variables, such as when executing function A, interrupt to execute function b    , it will cut over and then execute function A. The python process is implemented by the yield keyword.7. What is an adorner? Please use an adorner to implement the singleton adorner is essentially a Python function or class that allows other functions or classes to add extra functionality without any code modification, and the return value of the adorner is also a function/class object. defSingleton (cls,*args,**Kwargs): Instance= {}        def_singleton ():ifCls not inchInstance:instance[cls]= CLS (*args, * *Kwargs)returnInstance[cls]return_singleton @singletonclassTest_singleton (object):def __init__(self): Self.number=0defAdd (self): Self.num_add= 10obj_1=Test_singleton () obj_2=Test_singleton ()Print(obj_1,obj_2):8. Please use Python for quick sortingdefQuick_sort (my_list,start,end):ifStart <end:i,j=Start,end Base=My_list[i] whileI <J: while(I < J) and(My_list[j] >=base): J= J-1My_list[i]=My_list[j] while(I < J) and(My_list[i] <=base): I= i + 1My_list[j]=My_list[i] My_list[i]=base QuickSort (my_list,start,i-1) QuickSort (my_list,j+1, end)returnmy_list my_list= [42,30,61,80,74,20,24,45] Quick_sort (My_list,0,len (my_list)-1)    Print(my_list)9briefly describe the characteristics of MyISAM and InnoDB. MyISAM is suitable for applications that require a large number of queries, but is not very good for a lot of write operations. For example, if you just need to update a field, the entire table will be locked and other processes will be unable to manipulate the read process until the read operation is complete. In addition, MyISAM for select count (*This kind of calculation is very fast.    The InnoDB trend will be a very complex storage engine, which is slower than MyISAM for small applications, but supports ' row locks ', is more convenient when writing more, and supports more advanced applications such as transactions. 10. A brief description of the Python garbage collection mechanism the garbage collection in Python is based on the reference count, marked-supplemented by purge and generational collection.    Reference count: Python stores the reference technology for each object in memory, and if the count becomes 0, the object disappears and the memory allocated to the object is freed. Mark-Purge: Some container objects, such as List,dict,tuple,instace, may have a reference loop, and for these loops the garbage collector periodically recycles the loops (the objects are joined together by reference (pointers) to form a forward graph, which is the section of the object that makes up the graph.    Point, while the reference relationship forms the edge of the graph). Generational collection: Python divides memory into three generations based on the object's survival time, and after the object is created, the garbage collector assigns the generation to which it belongs. Each object is assigned a generation, and the younger generations assigned are prioritized, so the later objects are created more easily to be recycled. 

Python pen question (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.