Question 6: Find the output of the following program:
def gfg(x,l=[]): for i in range(x): l.append(i*i) print(l) gfg(3,[3,2,1]) |
chevron_right
filter_none
(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
Recommended Posts:
- Python-Quizzes | Python List Quiz | Question 13
- Python-Quizzes | Python List Quiz | Question 2
- Python-Quizzes | Python List Quiz | Question 22
- Python-Quizzes | Python List Quiz | Question 3
- Python-Quizzes | Python List Quiz | Question 4
- Python-Quizzes | Python List Quiz | Question 5
- Python-Quizzes | Python List Quiz | Question 7
- Python-Quizzes | Python List Quiz | Question 8
- Python-Quizzes | Python List Quiz | Question 9
- Python-Quizzes | Python List Quiz | Question 10
- Python-Quizzes | Python List Quiz | Question 11
- Python-Quizzes | Python List Quiz | Question 12
- Python-Quizzes | Python List Quiz | Question 14
- Python-Quizzes | Python List Quiz | Question 15
- Python-Quizzes | Python List Quiz | Question 16
- Python-Quizzes | Python List Quiz | Question 17
- Python-Quizzes | Python List Quiz | Question 18
- Python-Quizzes | Python List Quiz | Question 19
- Python-Quizzes | Python List Quiz | Question 20
- Python-Quizzes | Python List Quiz | Question 21

