March 2020
Beginner to intermediate
352 pages
8h 40m
English
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("\nSlicing characters from 3-12: ") print(String[3:12]) # Outputs:Slicing characters between 3rd and 2nd last character: loratory Data Analys print("\nSlicing 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.
Read now
Unlock full access