- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Remove the nth Index Character from a Non-Empty String
When it is required to remove a specific index character from a string which isn’t empty, it can be iterated over, and when the index doesn’t match, that character can be stored in another string.
Below is the demonstration of the same −
my_string = "Hi there how are you" print("The string is :") print(my_string) index_removed = 2 changed_string = '' for char in range(0, len(my_string)): if(char != index_removed): changed_string += my_string[char] print("The string after removing ", index_removed, "nd character is : ") print(changed_string)
The string is : Hi there how are you The string after removing 2 nd character is : Hithere how are you
A string is defined, and is displayed on the console.
An index value is defined.
The string is iterated over, and if the character in the string is not same as the index value that needs to be removed, the character is placed in a new string.
This new string is displayed as output on the console.
- Python program for removing nth character from a string
- Removing nth character from a string in Python program
- C# program to remove n-th character from a string
- PHP program to remove non-alphanumeric characters from string
- How to remove a particular character from a String.
- Python program to change character of a string using given index
- Python | Remove empty tuples from a list
- How to remove empty string/lines from PowerShell?
- Python program to Find the first non-repeating character from a stream of characters?
- Python Program to Remove the Characters of Odd Index Values in a String
- How to remove the last character from a string in Java?
- C# program to replace n-th character from a given index in a string
- How to remove an empty string from a list of empty strings in C#?
- First Non-Empty String in list in Python