What is the output of following code in Python?

>>> thelist=[‘a’,’b’]
>>> print thelist[3:]

Ans: The output of this code is following:
[]

Even though the list has only 2 elements, the call to thelist with index 3 does not give any index error.

Read the full book at www.amazon.com
Posted in Python, Python Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*