Strings Slicing in Python

String Slicing means to extract some portion of character or sub-string from the given string.

Syntax:
string[start:stop:step]

Parameters:
start - Starting index, where the slicing of strings starts.
stop - Ending index, where the slicing of strings stops.
Step - It is an optional argument that determines the increment between each index for slicing.


Slicing the string from index 0 to index 5 (stop index is not included)
mystr="Welcome to Neoogy"
print(mystr[0:5])

Output will be
Welco


Slicing the string from start to index 9 (stop index is not included) with alternate character.
mystr="Welcome to Neoogy"
print(mystr[0:9:2]) #Step is 2 for alternate character

Output will be
Wloet


0 Comments