What is the output of following Python Code?
g = [1, 0, 2, 0, 3]
g.remove(0)
print(g)
A) [1, 0, 2, 3]
B) [1, 2, 3]
C) [1, 2, 0, 3]
D) [0, 2, 0, 3]
Solution and Explanation:
The remove() method in Python removes the first occurrence of a specified value from a list. In the code you provided:
g = [1, 0, 2, 0, 3]
g.remove(0)
print(g)
The element 0 is removed from the list g, and the updated list is then printed. Therefore, the output will be:
[1, 2, 0, 3]
0 Comments:
Post a Comment