Skip to content

Python TypeError: String Index Out Of Range Solution

  • by
String Index Out Of Range Solution

A string is an array of characters and part of just about any programming language. In Python, the string index out of range means that which character you are finding that is not exit in your give list.

On this page, we are here to help out you to avoid this error. First of all, we want to show you one example that will give you this error.

let’s get started

String index out of range Solution


English = "A", "B","C", "D", "E"


Traceback (most recent call last):
     File "E:\py\", line 53, in <module>
IndexError: tuple index out of range

Above you can see the string index out of range came, why it came. Because we are taking something that does not exist.

The len() function

Every single programmer needs to know that The index starts from 0 and ends with the number of characters in the string. So, First need to know the len() of your variable to know the len() follow the below code. Get Length Of List In Python.

English = "A", "B","C", "D", "E"

For example:

You have a list of English characters such as make a  variable = [“A”, “B”, “C” “D”, “E”], you want to get C how will you get it? just print(English[2]) for more understanding follow the below code.

#          0    1   2    3    4
English = "A", "B","C", "D", "E"

Read More: Python IndexError: list assignment index out of range


Leave a Reply

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