- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
- Python 3 Advanced Tutorial
- Python 3 - Classes/Objects
- Python 3 - Reg Expressions
- Python 3 - CGI Programming
- Python 3 - Database Access
- Python 3 - Networking
- Python 3 - Sending Email
- Python 3 - Multithreading
- Python 3 - XML Processing
- Python 3 - GUI Programming
- Python 3 - Further Extensions
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.
- Related Articles
- Removing nth character from a string in Python program
- Python program for removing nth character from a string
- C# program to remove n-th character from a string
- Python program to change character of a string using given index
- PHP program to remove non-alphanumeric characters from string
- Python Program to Remove the Characters of Odd Index Values in a String
- How to remove a particular character from a String.
- C# program to replace n-th character from a given index in a string
- How to remove empty string/lines from PowerShell?
- Python | Remove empty tuples from a list
- Python program to Find the first non-repeating character from a stream of characters?
- How to remove the last character from a string in Java?
- How to remove an empty string from a list of empty strings in C#?
- Python – Remove strings with any non-required character
- Program to find the index of first Recurring Character in the given string in Python