1 1 vote Consider the following Python code:def append_to_lst(val, lst=[]): lst.append(val) return lst print(append_to_lst(1)) print(append_to_lst(2)) print(append_to_lst(3, []))What will be the output?$\verb|[1]|$$\verb|[2]|$$\verb|[3]|$ $\verb|[1]| $$\verb|[1, 2]| $$\verb|[3]|$ $\verb|[1]| $$\verb|[2]| $$\verb|[1, 2, 3]|$ $\verb|[1]| $$\verb|[1, 2]| $$\verb|[1, 2, 3]|$ Programming in Python goclasses gate2026_da_memorybased python-&-dsa python-programming one-mark + – GO Classes 310 views answer comment Share Follow Print See all 2 Comments 2 2 Comments reply GO Classes commented Feb 22 reply Follow flag Watch Detailed Video Solution Here! 0 0 replyShare mridulsingh289 commented May 18 reply Follow flag Trick Q, learned new concept 0 0 replyShare Please log in or register to add a comment.
1 1 vote Answer: B The key to this problem is understanding how default arguments are handled in Python. When lst=[] is used as a default argument, the same list object is created only once when the function is defined, not every time the function is called. Subsequent calls to the function without providing a new list will reuse and modify this single, shared list object. The first call, append_to_lst(1), uses the default list. The list becomes [1], and [1] is printed.The second call, append_to_lst(2), again uses the same default list object. The value 2 is appended to the existing list, making it [1, 2], and [1, 2] is printed.The third call, append_to_lst(3, []), explicitly provides a new, empty list ([]) as an argument. The value 3 is appended to this new list, making it [3], and [3] is printed.The output will therefore be:[1] [1, 2] [3] BooleanLattice answered Feb 17 BooleanLattice comment Share Follow 0 reply Please log in or register to add a comment.