+ 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.

6th Jul 2018, 5:04 PM
Maninder $ingh
Maninder $ingh - avatar
3 ответов
+ 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)
6th Jul 2018, 5:49 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 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
6th Jul 2018, 5:38 PM
E_E Mopho
E_E Mopho - avatar
+ 2
7th Jul 2018, 2:26 AM
Maninder $ingh
Maninder $ingh - avatar