Computer Science
Predict the output:
my_list= [ 'p', 'r', 'o', 'b', 'l' , 'e', 'm']
my_list[2:3] = []
print(my_list)
my_list[2:5] = []
print(my_list)
Python
Python List Manipulation
47 Likes
Answer
['p', 'r', 'b', 'l', 'e', 'm']
['p', 'r', 'm']
Working
mylist[2:3] = [] removes element at index 2 of mylist so it becomes ['p', 'r', 'b', 'l', 'e', 'm']. mylist[2:5] removes elements at indexes 2, 3, and 4 so now mylist becomes ['p', 'r', 'm'].
Answered By
18 Likes
Related Questions
Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88], which function can change the list to:
- [3, 4.5, 12, 25.7, 88]
- [3, 4.5, 12, 25.7]
- [ [2, 1, 0, 5], 88]
What will the following code result in?
L1 = [1, 3, 5, 7, 9] print (L1 == L1.reverse( ) ) print (L1)Predict the output:
List1 = [13, 18, 11, 16, 13, 18, 13] print(List1.index(18)) print(List1.count(18)) List1.append(List1.count(13)) print(List1)Predict the output:
Odd = [1,3,5] print( (Odd +[2, 4, 6])[4] ) print( (Odd +[12, 14, 16])[4] - (Odd +[2, 4, 6])[4] )