Write a program to access a range of character in the string in python
Answers
Answered by
1
Answer:
String Slicing
To access a range of characters in the String, method of slicing is used. Slicing in a String is done by using a Slicing operator (colon).
Explanation:
# Python Program to
# demonstrate String slicing
# Creating a String
String1 = "Archit Pathak"
print("Initial String: ")
print(String1)
# Printing 3rd to 13th character
print("\nSlicing characters from 3-13: ")
print(String1[3:13])
# Printing characters between
# 3rd and 2nd last character
print("\nSlicing characters between " +
"3rd and 2nd last character: ")
print(String1[3:-2])
OUTPUT:-
Initial String:
Archit Pathak
Slicing characters from 3-13:
hit Pathak
Slicing characters between 3rd and 2nd last character:
it Path
Please Mark it as Brsinliest
And Follow me
Similar questions