
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Removing nth character from a string in Python program
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 gfor 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 learnt about the removal of ith character from a given input string in Python 3.x or earlier
- Related Articles
- Python program for removing nth character from a string
- 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?
- Insert a character at nth position in string in JavaScript
- String function to replace nth occurrence of a character in a string JavaScript
- C# Program to change a character from a string
- Removing adjacent duplicates from a string in JavaScript
- Python program to find Most Frequent Character in a String
- Python program to find Least Frequent Character in a String
- C# Program to replace a special character from a String
- Get the Nth character of a string in the Swift programming language
- Removing a specific substring from a string in JavaScript
- Removing punctuations from a string using JavaScript
