Python program to remove a character from a specified index in a string

Here, we will figure out how to expel a character from a predefined file in a string utilizing python program?

Given a string and a record, we need to expel the character from the given list in the string utilizing python program.

Here, we would figure out how we can expel a character from a list in a string effectively?

Question:

We are given a non-void string and a number N, with the end goal that we need to restore a string to such an extent that the character at the given record (N) has been evacuated. Where N has a place with the range from 0 to len(str)- 1.

Example:

    remove_char ('raman', 1) = 'rman'
    remove_char ('raman', 0) = 'aman'
    remove_char ('raman', 4) = 'rama'

Code:

def remove_char(str, n):
    front = str[:n]  # up to but not including n
    back = str[n + 1:]  # n+1 till the end of string
    return front + back

print (remove_char('JustTechReview', 3))
print (remove_char('Hello', 4))
print (remove_char('Website', 1))

Output:

JustechReviw
Hell
Wbsite

Leave a Comment

error: Alert: Content is protected!!