Computer Science
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)
Answer
1
2
[13, 18, 11, 16, 13, 18, 13, 3]
Working
List1.index(18) gives the first index of element 18 in List1 which in this case is 1. List1.count(18) returns how many times 18 appears in List1 which in this case is 2. List1.count(13) returns 3 as 13 appears 3 times in List1. List1.append(List1.count(13)) add this 3 to the end of List1 so it becomes [13, 18, 11, 16, 13, 18, 13, 3].
Related Questions
What will the following code result in?
L1 = [1, 3, 5, 7, 9] print (L1 == L1.reverse( ) ) print (L1)
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:
Odd = [1,3,5] print( (Odd +[2, 4, 6])[4] ) print( (Odd +[12, 14, 16])[4] - (Odd +[2, 4, 6])[4] )
Predict the output:
a, b, c = [1,2], [1, 2], [1, 2] print(a == b) print (a is b)