+ 2
Why output is 4,9
def s(a=2,b=2): a,b=b,a v=a**b return v print([s(2,3),s()][::-1]) output =[4,9] but why i don't know can you clear me.
3 Antworten
+ 6
def s(a = 2, b = 2): # a and b will be 2 if not provided
a, b = b, a # Swapping a and b
v = a**b # a*a*...*a (b times)
return v
print([s(2,3), s()][::-1]) # [9, 4][::-1] = [4,9] (list[::-1] reverses list)
+ 4
s(2,3) returns 9.
s() returns 4 using the default values of a and b
so u get [9,4].
the [::-1] reverses the list so you get [4,9] printed
+ 2
Thanks Mert Yazıcı and E_E Mopho.