- 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
Removing nth character from a string in Python program
In this article, we will learn about the solution to the problem statement given below −
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 −
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))
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 −
In this article, we learnt about the removal of ith character from a given input string in Python 3.x or earlier
- 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?
- C# Program to change a character from a string
- C# Program to replace a special character from a String
- How to delete a character from a string using python?
- C# program to remove n-th character from a string