Python-Quizzes | Python List Quiz | Question 6

Question 6: Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

def gfg(x,l=[]): 
    for i in range(x): 
        l.append(i*i) 
    print(l) 
  
gfg(3,[3,2,1]) 

chevron_right


(A) [3, 2, 1, 0, 1, 4]
(B) [0, 1, 0, 1, 4]
(C) [0, 1]
(D) [ ]


Answer: (A)

Explanation: l is a name for a variable that points to a list stored in memory. The function call starts off by creating a new list in a new block of memory. l then refers to this new list. It then appends 0, 1, and 4 to this new list. So that’s great.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.