Tell me what Do You Think Is The Output Of The Following Code Fragment? Is There Any Error In The Code?
Submitted by: Muhammadlist = ['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.
Submitted by: Muhammad
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.
Submitted by: Muhammad
Read Online Python Developer Job Interview Questions And Answers
Top Python Developer Questions
☺ | Do you know what Is The Key Difference Between A List And The Tuple? |
☺ | Tell me how Does The Ternary Operator Work In Python? |
☺ | Do you know what Does The <Yield> Keyword Do In Python? |
☺ | Tell me what is PEP 8? |
☺ | Tell me what are the built-in type does python provides? |
Top Web Developer Categories
☺ | Bootstrap Interview Questions. |
☺ | Front End Web Developer Interview Questions. |
☺ | Typography Interview Questions. |
☺ | Laravel PHP Developer Interview Questions. |
☺ | Junior Developer PHP Interview Questions. |