- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 for removing n-th character from a string?
In this article, we will remove the nth character from a string in Python. Let’s say we have the following input string −
Amitdiwan
The output should be the following after removing nth character i.e. 2nd index −
Amt
Python program for removing n-th character from a string
In this example, we will remove the nth character from a string −
Example
def removechar(str1, n): x = str1[ : n] y = str1[n + 1: ] return x + y # Driver Code if __name__ == '__main__': str1 = input("Enter a String =") n = int(input("Enter the n-th index =")) print("The new string =\n") print(removechar(str1, n))
Output
Enter a String= Jacob Enter the n-th index = 2 The new string = Jaob
Python program for removing n-th character from a string without user input
In this example, we will remove the nth character from a string without user input −
Example
def removechar(myStr, n): x = myStr[ : n] y = myStr[n + 1: ] return x + y # Driver Code if __name__ == '__main__': myStr = "Hello" print("String = ",myStr) # nth index # character to be removed at this index n = 2 print("The new string = ",removechar(myStr, n))
Output
String = Hello The new string = Helo
Python program for removing n-th character from a string using for loop
In this example, we will remove the nth character from a string using for loop −
Example
# Create a String myStr = "How are you?" # Display the initial string print("String = ",myStr) # nth index # The character is to be removed at this index n = 9 newStr = '' # for loop iteration for char in range(0, len(myStr)): if(char != n): # append newStr += myStr[char] # Display the updated string print("Updated string = ",newStr)
Output
String = How are you? Updated string = How are yu?
- Related Articles
- Java program for removing n-th character from a string
- 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
- C# program to replace n-th character from a given index in a string
- Python Program for n-th Fibonacci number
- Python Program to Get a Character From the Given String
- Program to find Kth bit in n-th binary string using Python
- Removing n characters from a string in alphabetical order in JavaScript
- Find k-th character of decrypted string - Set – 2 in Python
- Find sum by removing first character from a string followed by numbers in MySQL?
- C Program for n-th even number
- C Program for n-th odd number
- Java Program for n-th Fibonacci number
- N-th Fibonacci number in Python Program

Advertisements