Computer Science
Which line of code will cause an error ?
1. num= [5, 4, 3, [2], 1]
2. print(num[0])
3. print(num[3][0])
4. print(num[5])
- Line 3
- Line 2
- Line 4
- Line 1
Python List Manipulation
2 Likes
Answer
Line 4
Reason — Index 5 is out of range because list has 5 elements which counts to index 4.
Answered By
1 Like
Related Questions
Which line of code produces an error ?
- "one" + 'two'
- 1 + 2
- "one" + "2"
- '1' + 2
What is the output of this code ?
>>> int("3" + "4")
- "7"
- "34"
- 34
- 24
Which is the correct form of declaration of dictionary ?
- Day = {1:'Monday', 2:'Tuesday', 3:'wednesday'}
- Day = {1;'Monday', 2;'Tuesday', 3;'wednesday'}
- Day = [1:'Monday', 2:'Tuesday', 3:'wednesday']
- Day = {1'monday', 2'tuesday', 3'wednesday'}
Identify the valid declaration of L:
L = ['Mon', '23', 'hello', '60.5']
- dictionary
- string
- tuple
- list