Python Developer Question:
Download Questions PDF

Tell me what Do You Think Is The Output Of The Following Code Fragment? Is There Any Error In The Code?

Python Developer Interview Question
Python Developer Interview Question

Answer:

list = ['a', 'b', 'c', 'd', 'e']
print (list[10:])
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 an opening index that surpasses the no. of items in the list won’t result in an IndexError. It will just return an empty list.

Download Python Developer Interview Questions And Answers PDF

Previous QuestionNext Question
Please explain when Is The Python Decorator Used?Tell me how Do You Debug A Program In Python? Is It Possible To Step Through Python Code?