coding180 icon
Coding180

What is the output of the following code snippet? Are there errors in the code?

Home > Interviews > Python


robort - 2022-08-30 10:07:39

list = ['a', 'b', 'c', 'd', 'e']
print (list[10:])

The result of the above lines of code is []. There will be no errors like IndexError.
Attempting to get a member from a list with an index that exceeds the member count (eg, trying to access the one given in the question list[10]) raises an IndexError

By the way, only retrieve slices that exceed the number at the starting index. Items in the list do not cause IndexError. It just returns an empty list.


user

Robort Gabriel

Lagos, Nigeria

Freelance Web Developer, Native Android Developer, and Coding Tutor.

Skills
  • UI / UX
  • JavaScript
  • Python
  • PHP
  • Kotlin
  • Java
  • Bootrap
  • Android
  • Laravel