Computer Science
Predict the output:
Odd = [1,3,5]
print( (Odd +[2, 4, 6])[4] )
print( (Odd +[12, 14, 16])[4] - (Odd +[2, 4, 6])[4] )
Python
Python List Manipulation
42 Likes
Answer
4
10
Working
Odd + [2, 4, 6] will return [1, 3, 5, 2, 4, 6]. The element at index 4 of this list is 4 so the first output is 4. (Odd +[12, 14, 16])[4] is 14 and (Odd +[2, 4, 6])[4] is 4. 14 - 4 = 10 which is the second output.
Answered By
19 Likes
Related Questions
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)
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:
a, b, c = [1,2], [1, 2], [1, 2] print(a == b) print (a is b)
Predict the output of following two parts. Are the outputs same? Are the outputs different? Why?
(a)
L1, L2 = [2, 4] , [2, 4] L3 = L2 L2[1] = 5 print(L3)
(b)
L1, L2 = [2, 4] , [2, 4] L3 = list(L2) L2[1] = 5 print(L3)