Python Programming - Variables - Discussion
Discussion Forum : Variables - General Questions (Q.No. 27)
27.
What is the output of the following code:
my_list = [1, 2, 3, 4]
my_list[1:3] = [5, 6]
print(my_list)
Answer: Option
Explanation:
In this code, a list my_list
is defined with four elements.
The second line uses slice assignment to replace the second and third elements of the list with the new list [5, 6]
.
When the modified list is printed to the console, the output is [1, 5, 6, 4]
.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers