How to Index Strings in Python

Indexing is the process of finding a specific element within a sequence of elements through the element's position. Remember that strings are basically sequences of characters. We can use indexing to find a specific character within the string.

  • If we consider the string from left to right, the first character (the left-most) is at position 0.
  • If we consider the string from right to left, the first character (the right-most) is at position -1.

The table below illustrates this for the phrase "MONTY PYTHON".

Python Indexing

The following code shows how to find characters by position using indexing.

phrase = "Monty Python"

first_letter = phrase[0]
#[M]onty Python

last_letter = phrase[-1]
#Monty Pytho[n]

fifth_letter = phrase[4]
#Mont[y] Python

third_letter_from_end = phrase[-3]
#Monty Pyt[h]on

The expected output for each call to print() is shown in square brackets in the preceding comment.

Related Video

Author: Nat Dunn

Nat Dunn is the founder of Webucator (, a company that has provided training for tens of thousands of students from thousands of organizations. Nat started the company in 2003 to combine his passion for technical training with his business expertise, and to help companies benefit from both. His previous experience was in sales, business and technical training, and management. Nat has an MBA from Harvard Business School and a BA in International Relations from Pomona College.

Follow Nat on Twitter at @natdunn and Webucator at @webucator.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.