Here in this article, we have provided python source code which can remove all punctuations from a string.
Prerequisite topics to create this program
- Python For loop
- Python String
- Python in operator
- Python if...else statements
Steps
- Ask the user to enter a string.
- Create a string that contains all the punctuations.
- create an empty string.
- now loop through the user entered string and add only those characters in the empty string which are not punctuations.
Python Program to Remove Punctuations From a String
Code
string = input("Enter the String: ")
punc= '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
new_string=""
for i in string:
if not i in punc:
new_string+=i
print("The String without puctuation is: \n", new_string)
Output 1
Enter the String: Hello !! this is tech geek buzz **** and we welcome you all-------
The String without punctuation is:
Hello this is tech geek buzz and we welcome you all
Output 2
Enter the String: **TehcGeekBuzz!!! Welcome User!!!^&
The String without punctuation is:
TehcGeekBuzz Welcome User
People are also reading:
- Python Program to Display Calendar
- Python Program to Swap Two Variables
- How to Find Square Root in Python?
- WAP in C++ & Python & sort an Array Using Bubble Sort
- WAP Using Switch Case to Check whether the given alphabet is a vowel or Not
- Linear Search in Python and C++
- WAP in using the switch case to print the Equivalent name of the day on the basis of user input
- Programming in C and Java to convert from octal to decimal
- WAP to check whether a given character is an alphabet, digit or any special character
- Python Program to Find Numbers Divisible by Another Number
Leave a Comment on this Post