Can someone please help with this ? Thanks | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone please help with this ? Thanks

def testFunc(x, y = []): y.append(x) return y a= testFunc(1) b= testFunc(2,[]) c= testFunc(3) print(c)

17th Oct 2020, 3:39 PM
Curious Ant
Curious Ant - avatar
2 Answers
+ 3
Print(c) prints [1,3] >To a* you assigned testFunc(1) here you have passed 1 as parameter to the testFunc(x,y=[]) ...empty list of y will be appended with 1 so ,we will have 1 in y like y=[1] will be returned. >To b* you assigned testFunc(2,[]) passing 2 parameter with 1 empty list too so ,as we pass that empty list will be appended with 2 so this will return [2]. >To c* you assigned testFunc(3) and here you are passing only 1 parameter that's 3,we have y with 1 already so this 3 will be appended to that existing list containing 1,since you printed c . It outputs [1,3]
17th Oct 2020, 4:18 PM
chaithra Gowda
chaithra Gowda - avatar
+ 1
a, b return not printed c printed return [3] [].append(3)= [3]
17th Oct 2020, 4:01 PM
Shadoff
Shadoff - avatar