Chapter 13: String Slicing

In this chapter, we will learn how to extract a substring from a given string by specifying the start and stop positions.

 

Syntax: [Start argument : Stop argument]

 

The start argument defines the position where the extraction begins, and the stop argument defines where it ends. Note that the stop argument is exclusive, meaning it refers to the position just before the specified stop index.

 

For example, if we want to extract the substring Learn from the string Free Learning, the indexing will go from 5 to 10. Here, 10 corresponds to the position of the i, but the stop argument will exclude it. So, the result will include the characters at positions 5, 6, 7, 8 and 9, which are "L", "e", "a", "r" and "n".

 

  F r e e   L e a r n i n g
Indexing 0 1 2 3 4 5 6 7 8 9 10 11 12
 
name = "Free Learning"
print(name[5:10])
Output: Learn