run time
Python uses adorner and thread to limit the execution time of functions
A magical device for Python decorators
Implementing the dry (non-repeating code) principle through the Python adorner
For the adorner of a class method, someone gives the following scenario:def decorator (args): def _deco (func): def _func (self):
class, the Read method is not defined, so let's try to see if the contents of the file can be read.F1 = File_handle (' a.txt ', mode= "R") # initializes the object, and passes the argument, opening the A.txt file with the class you created.F1.read ()Output:Hello world\n#成功调用了文件对象的read方法, and there is no way to use inheritance.#接着在试着调用wirte方法在文件中写内容 to see if the original write function of the file object has been changed.F1 = File_handle (' a.txt ', mode= "w")F1.seek (0)F1.write ("aaaaaaaaaaa\n
facilitate the resumption of execution from the mark points at the next call. Yield causes a function to be converted to a generator, which in turn returns an iterator.The difference between 18.os.path and Sys.path?The OS module is responsible for the interaction between the program and the operating system, provides access to the underlying interface of the operating system, and the SYS module is responsible for the interaction between the program and 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
Big data now in the country's strong support, more and more fiery, attracted a large number of people to learn, learn how to apply for jobs. Interview is a learning, how to interview success. What is the secret of the interview? Take a look at the advice I give (all the experience). Of course, to have enough technical skills to interview, to do a good job interview questions, the following small series on the disclosure of 16 of the most classic Python
this function is only used in this one place, even the name is very casual circumstances;2, anonymous function, generally used to give filter,map such a function-type programming services;3, as a callback function, passed to some applications, such as message processingPersonal Understanding:1. No need to define function name (temporary function)2. Only simple operation, and return value, no complex function bodyFour. Describe the use of the range () function under
programming services;3, as a callback function, passed to some applications, such as message processingPython allows you to define a small single-line function.The form of a lambda function is defined as follows:Labmda parameter: The expression lambda function returns the value of an expression by default.You can also assign it to a variable. A lambda function can accept any parameter, including optional arguments, but the expression has only one:>>> g = lambda x, y:x*y>>> g (3,4)12>>> g = lamb
)]Question five: What will the output of the following code be? Say your answer and explain?def extendList(val, list=[]): list.append(val) return listlist1 = extendList(10)list2 = extendList(123,[])list3 = extendList(‘a‘)print "list1 = %s" % list1print "list2 = %s" % list2print "list3 = %s" % list3How you will modify extendList the definition to produce the desired resultThe output of the above code is:list1 = [10, ‘a‘]list2 = [123]list3 = [10, ‘a‘]Many people mistakenly think that list1 s
?
__NAME__: A convention in which Python's internal name is used to distinguish itself from user-defined names, preventing collisions
_name: A convention used to specify the private variables of a variable
__name: The interpreter uses _classname__name instead of the name to distinguish it from other classes of the same naming
To learn more about the difference between the two, click: Underline in Python(12), say a
nothing else but records the type of the class and the specific object.The multi-inheritance class of 3.Python ensures that functions of each parent class are called one at a time by means of MRO, and that each parent class function is called only once (if each class uses Super).An example of a use of the Super function:Inherit the Dict class and make an ordered dictionary type based on the Dict class.Class Mydict (dict): #有序字典实现def __init__ (self):S
application scenarios?136. Describe pipreqs and application scenarios?137. What code-checking tools are used in Python?138. Describe the role of saltstack, ansible, Fabric, puppet tools?What is the difference between 139.B tree and B + tree?140. Please list common sorts and implement any three of them by code.141. Please list common lookups and implement any three of them by code.142. Please list the design patterns you are familiar with?143. Have yo
Describe the most recently encountered Python interview questions, you can refer to the following1. Construct a memory leak scenario2. Generate a Fibonacci sequence with generator3. Construct a connection class that can be used with, ConnectionPool class4. Decorating Fu A function of calculating function consumption time5. Construct a function that can be cached_property6.mysql Optimization, usage specification7.windows
cut, because 3 >1*2, the optimal coefficient group is 3 Li=[0,1,2,3] iflength==0: #当长度为0时, return 0return 0 iflength==1: #当长度为1时, return 1return 1 iflength==2: #当长度为2时, return 2return 2 iflength==3: #当长度为3时, return 2, although the optimal coefficient group is 2, but every time you have to cut a knife, so 1*2=2, so the length is 3 o'clock or 2.return 2 forJinchRange4, length+1): Max=0 forIinchRange1, J): # idea: Each time the value is solved, the other less than the lengt
) + walk_stairs (stairs-2) # 2, to a staircase, from the bottom to go up, every time you can walk 1 to n steps, how many ways to go? # on the 1 steps # 2 steps on the 3 steps on the 4# 4 steps on the 8# on the N Steps 2^ (n-1) # 3, to a staircase, from the bottom to go up, each can walk 1 steps or 2 steps or 3 steps, how many kinds of the total number of methods to go? # on 1 steps 2^ (1-1) # 2 steps 2^ (2-1) # on 3 steps 2^ (3-1) # f (n) = f (n-1) + f (n-2) + f (n-3)2, to a character array, the
implement?The 5.Python function often has *args,**kwargs these two parameters, what do they mean, why use them?Variable scopes in 6.Python (variable lookup order).7. What will be the output of this code? Please explain.8. Describe the concept of the Python Gil, and its impact on Python multi-threading? Write a multi-t
: list,dict,set, immutable: String,tuple,numberWhat is the 9.python generator?A generator is a mechanism for implementing iterators, and its functional implementation relies on yield expressions, in addition to normal functions;Its working mechanism: a function with yield returns a Iterable object through __next__ each execution to the yield return value, the next time next comes from the yield next sentence continues to execute, until meeting return
about __slots__ is that it can be used as an encapsulation tool to prevent users from adding new properties to an instance. Although the use of __slots__ can achieve this goal, but this is not its original intention. More is used as a memory optimizer tool.Four. Demonstration of how to use __slots__.Example 1:Class Foo:__slots__= ' x 'F1=foo ()F1.x=1f1.y=2# ErrorPrint (f1.__slots__) #f1不再有__dict__Class Bar:__slots__=[' x ', ' Y ']N=bar ()n.x,n.y=1,2n.z=3# ErrorExample 2: (Validation of __slots_
The following is an example of using a decorator for a class to temporarily add properties or methods to a defined class through the form of an adorner.def add_property (**kwargs):def deco (obj):For Key,value in Kwargs.items ():SetAttr (Obj,key,value)return objReturn deco@ add_property (a=1,b=2,c=3)Class Test:PassT1 = Test ()Print Test.aPrint test.bPrint test.cOutput:123This adorner can be used not only in classes, but also on objects.This article is from the "Rebirth" blog, make sure to keep th
Class (definition)Static attribute class attributes (variables) are written directly in the class, all uppercaseDynamic property method (function) SelfClass method @classmethodd CLSStatic methods @staticmethod No default parametersThe elective system is specially prepared for the function of object-oriented programming.Feature @propertyclass Person : @staticmethod def login (): passclass Teacher (person): PassCallThe name of the object. Dynamic attribute () class name. Dynamic P
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.