
- 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 program for removing nth character from a string
In this article, we will learn about the solution to the problem statement given below −
Problem statement − We are given a string, we have to remove the ith indexed character from the given string and display it.
In any string in Python, indexing always starts from 0. Suppose we have a string “tutorialspoint” then its indexing will be done as shown below −
T u t o r i a l s p o i n t 0 1 2 3 4 5 6 7 8 9 10 11 12 13
Now let’s see the Python script for solving the statement −
Example
def remove(string, i): # slicing till ith character a = string[ : i] # slicing from i+1th index b = string[i + 1: ] return a + b # Driver Code if __name__ == '__main__': string = "Tutorialspoint" # Remove nth index element i = 8 print(remove(string, i))
Output
Tutorialpoint
Algorithms − From the given input string, i-th indexed element has to be popped. So, Split the string into two parts, before indexed character, and after indexed character thereby leaving the ith character Return the merged string.
Here we have three variables declared in global scope as shown below −
Conclusion
In this article, we learned about the removal of ith character from a given input string in Python 3.x or earlier
- Related Articles
- Removing nth character from a string in Python program
- Python program for removing n-th character from a string?
- Java program for removing n-th character from a string
- Python Program to Remove the nth Index Character from a Non-Empty String
- Find sum by removing first character from a string followed by numbers in MySQL?
- Python Program for nth Catalan Number
- C# Program to change a character from a string
- String function to replace nth occurrence of a character in a string JavaScript
- Insert a character at nth position in string in JavaScript
- C# Program to replace a special character from a String
- Removing punctuations from a string using JavaScript
- How to delete a character from a string using python?
- C# program to remove n-th character from a string
- Java Program to Get a Character From the Given String
- Python program to find Most Frequent Character in a String
