0

Code 1.Please explain this code.

def x(a=0): def y(b=a): return a + b if a == 0: return y return y(a) print(x()(3))

24th Nov 2020, 6:19 AM
Rajan K
Rajan K - avatar
1 Odpowiedź
+ 1
Lets read it from the bottom, print x() so x is a function or def which you can see in the first line , inside of the x we see 'a' as a variable is equal to 0 it means x function shoud have an input otherwise manually puts 0 for a x(a=0) return(a) Print(x() ) #0 Print(x(3)) #3 The same happens to the y function and its inside x function ,it means if x function called go and then call y function and do whatever is inside it(in this case a+b) then check the if statement
26th Nov 2020, 9:23 PM
Shakila Habibi Rezaei
Shakila Habibi Rezaei - avatar