Python program to remove the i-th character from a string

In any line, indexing always starts from 0. Suppose we have lines obsessed with it, then its indexing will be as follows:

 geeks 0 1 2 3 4 


 Input: Geek i = 1 Output: Gek Input: Peter i = 4 Output: Pete 

Approach: from the given line, the i-th indexed element must be removed. So, split the string into two halves, before the indexed character and after the indexed character. Return the concatenated string.

Below is the implementation of the above approach:

# Python3 program to remove the i-th
# indexed character from string

# Removes character at index i

def remove (string, i): 


# Characters before indexing i

# stored in variable a

a = string [: i] 


  # Characters after indexing nth

# stored in variable b

b = string [i + 1 :]


  # Return the string after deletion

  # nth indexed character.

  return a + b

Driver code

if __ name__ = = `__main__` :


string = " geeksFORgeeks "


# Remove the nth index element

i = 5


  # Print a new line

print (remove (string, i))