VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-index-and-slice-strings-in-python/

⇱ How to Index and Slice Strings in Python? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Index and Slice Strings in Python?

Last Updated : 15 Jul, 2025

In Python, indexing and slicing are techniques used to access specific characters or parts of a string. Indexing means referring to an element of an iterable by its position whereas slicing is a feature that enables accessing parts of the sequence.

Indexing Strings in Python

String Indexing allows us to access individual characters in a string. Python treats strings like lists where each character is assigned an index, starting from 0. We can access characters in a String in Two ways :

  1. Accessing Characters by Positive Index Number
  2. Accessing Characters by Negative Index Number
👁 Image
Indexing in Python

Accessing by Positive Index Number

In this type of Indexing we pass a Positive index (which we want to access) in square brackets. The index number starts from index number 0 (which denotes the first character of a string).


Output
G
f
G

Accessing by Negative Index Number

In this type of Indexing, we pass the Negative index(which we want to access) in square brackets. Here the index number starts from index number -1 (which denotes the last character of a string). Example 2 (Negative Indexing) :


Output
!
e
o

Slicing Strings in Python

String Slicing allows us to extract a part of the string. We can specify a start index, end index, and step size. The general format for slicing is:

string[start : end : step]

  • start : We provide the starting index.
  • end : We provide the end index(this is not included in substring).
  • step : It is an optional argument that determines the increment between each index for slicing.

Output
Gee
ek
!seGrf
Comment
Article Tags:
Article Tags: