Question:
Write a python program to remove punctuations from a string
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# define punctuation punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~''' my_str = input("Enter a string: ") # remove punctuation from the string no_pt = "" for char in my_str: if char not in punctuations: no_pt = no_pt + char # display the unpunctuated string print(no_pt) |
Explanation:
There are fourteen punctuation marks commonly used in English grammar. They are the period, question mark, exclamation point, comma, semicolon, colon, dash, hyphen, parentheses, brackets, braces, apostrophe, quotation marks, and ellipsis.
Output:
1 2 |
Enter a string: GlobalSQA!! on^ the& swing)( GlobalSQA on the swing |
Leave a Reply