in Python by
What Do You Think Is The Output Of The Following Code Fragment? Is There Any Error In The Code?

list = ['a', 'b', 'c', 'd', 'e']

print (list[10:])

1 Answer

0 votes

The result of the above lines of code is []. There won’t be any error like an IndexError.

You should know that trying to fetch a member from the list using an index that exceeds the member count (for example, attempting to access list[10] as given in the question) would yield an IndexError. By the way, retrieving only a slice at the starting index that surpasses the no. of items in the list won’t result in an IndexError. It will just return an empty list.

Related questions

0 votes
asked Feb 11, 2020 in Python by rahuljain1
0 votes
asked Jun 24, 2020 in Python by Robindeniel