Slicing Strings in Python
Contents
What is String Slicing in Python:
Slicing a String is to specify a range of characters of a String, here is an example:
a = "Hello, its time to learn, LearDuty"
print(a[2:9])
Output:
llo, it
Slice From the Start in Python
a = "Hello, its time to learn, LearDuty"
print(a[:9])
Output:
Hello, it
Slice To the End in Python
a = "Hello, its time to learn, LearDuty"
print(a[2:])
Output:
llo, its time to learn, LearDuty
Slicing with Negative Index in Python
Get the last two characters in a String in Python:
a = "Hello, its time to learn, LearDuty"
print(a[-2:])
Output:
ty