Program to remove Punctuation from a string in Python

Program to remove Punctuation from a string in Python. The program involves input, print function, for iterative loop and initialization of a string. This is for class 11,12 , Beginners and B Tech computer science students.

Program to remove Punctuation from a string

Punctuation is the use of spacing, conventional signs, and certain typographical devices as aids to the understanding and correct reading of written text, whether read silently or aloud.

Algorithm:

The punctuation is defined. ””’!()-[]{};:'”\,<>./[email protected]#$%^&*_~”’
Input from the user is taken. Enter a string: This () is * / a & good %day.
punctuation is removed
Display the unpunctuated string.

Source code :

i=0
# define punctuation  
punctuation = '''''!()-[]{};:'"\,<>./[email protected]#$%^&*_~'''  #these are the various punctuation
# take input from the user  
my_str = input("Enter a string: ")  
# remove punctuation from the string  
no_punct = ""  
for char in my_str:  
   if char not in punctuation:  
       no_punct = no_punct + char  
# display the unpunctuated string  
print(no_punct)
#print(i)

Source code Explanation :

step 1:define punctuation
punctuation = ””’!()-[]{};:'”\,<>./[email protected]#$%^&*_~”’
Step 2:take input from the user
my_str = input(“Enter a string: “)
step 3:remove punctuation from the string
no_punct = “”
for char in my_str:
if char not in punctuation:
no_punct = no_punct + char
step 4: display the unpunctuated string
print(no_punct)

Output:

 RESTART: C:/csstudy/source code file 2/Python Program to Remove Punctuation from a String.py 
Enter a string: This () is * / a & good %day.
This  is   a  good day
>>> 

Output Explanation:

RESTART: C:/csstudy/source code file 2/Python Program to Remove Punctuation from a String.py
step 1: Entering a string
Enter a string: This () is * / a & good %day.
step 2: Output of the string after removing punctuation
This is a good day

Conclusion :

The program is running fine.

Thank you for reading, learning and copying the Program to remove Punctuation from a string in Python. The program involves input , print function , for iterative loop and initialization of a string. This is for class 11,12 , Beginners and B Tech computer science students. Below are the links provided for more programs, class 11,12 practical file and project file :
/category/python-programs/
Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study
Computer Science Practical file for class 12 Term-2 – CS Study
Python Projects for Class 12 with Source Code (Mysql Connectivity) – CS Study

Leave a Comment

Your email address will not be published.