To access a range of characters in a string, a slicing method is used. Slicing in a string is done using a slicing operator (:). Here's a program that demonstrates string slicing:
# Creating a String
String = "Exploratory Data Analysis"
# Outputs: Slicing characters from 3-12:loratory
print(" Slicing characters from 3-12: ")
print(String[3:12])
# Outputs:Slicing characters between 3rd and 2nd last character: loratory Data Analys
print(" Slicing characters between " + "3rd and 2nd last character: ")
print(String[3:-2])
The output of each code block is displayed with an inline comment, which makes it easier to comprehend.