Home > other >  Python function of nested invocations
Python function of nested invocations

Time:11-21

Def peven (n) :
I=0
S=0.0
For I in range (2, n + 1, 2) :
S +=1.0/I
Print (s)
The return (s)

Def podd (n) :
S=0.0
For I in range (1, n + 1, 2) :
S +=1.0/I
The return (s)

Def dcall (fp, n) :
S=fp (n)
The return (s)


If __name__=="__main__ ':
N=int (input (' input a number: \ n '))
If n % 2==0:
Sum=dcall (peven, n)
The else:
Sum=dcall (podd, n)

Print (sum)


It s=fp (n) of how to understand this? If no dcall function, the above two () function returns the result

CodePudding user response:

Fp parameter passed in is an object, you can understand for the above two functions are reached the dcall, fp represents one of them, of course, you can use these two functions, can use a class to, for example, dcall is monitor, you are the teacher in charge, do you want to convey there is no class today, you notice the monitor, let the monitor is ok to inform the class; If there is no dcall, you a a person to inform yourself

CodePudding user response:

reference 1st floor without a white reply:
fp parameter passed in is an object, you can understand for the above two functions are reached the dcall, fp represents one of them, of course, you can use these two functions, can use a class to, for example, dcall is monitor, you are the teacher in charge, do you want to convey there is no class today, you notice the monitor, let the monitor is ok to inform the class; If there is no dcall, you a a person to inform yourself
first sentence is not exact, because python everything just object types, I generally prefer to directly say pass in a function address or function, uh... Of course, the beginners do not need to pay attention to that
  • Related