string index out of range python code example
Example 1: IndexError: list index out of range
# This means that you have tried to access an
# index that is not within the range of your list!
# For example, if your list is
exampleList = [0, 1, 2, 3, 4]
# then you can't access
exampleList[5]
# because lists are indexed from 0 in most languages,
# so the last index in exampleList is 4.
# You might typically see this inside a for loop where you're
# iterating through the list, but maybe it looped past the last index.
Example 2: String index out of range: 7
package com.yawintutor;
public class StringSubstringCharAt {
public static void main(String[] args) {
String str = "Bangalore";
String str2;
str2 = str.substring(3, 8);
System.out.println("Given String : " + str);
System.out.println("Output String : " + str2);
}
}