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])    
  1. Line 3
  2. Line 2
  3. Line 4
  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