How to Remove Specified-located Character from a String in Python


This example will teach us how to delete characters of a specified location from a non-empty string in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

str = input("Please input the string: ")
n = int(input("Please input the index to be deleted: "))
first = str[0:n]
last = str[n+1:]
newStr = first + last
print("New string is: ", newStr)

Output:

Please input the string: Hello World
Please input the index to be deleted: 4
New string is: Hell World
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments