• Register
1 vote



I am starting my programming experience with python recently. I’ve been surfing over the internet for a program that can remove punctuation from a String. I’ve found many of them but still can’t understand them. I am looking for a program written in very basic codes. If possible, please write me a program which would be easy to understand for me.


12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Hello Gavin.

I hope you are doing great today.  It’s nice to someone asked a question in a polite way and briefly.

I’ve snippet a program below and tried to make it as simple as possible for your better understanding.

# define punctuation
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''

my_str = "Hello!!!, My name --- is Gavin."

# To 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 punctuations:
       no_punct = no_punct + char

# display the unpunctuated string

This basic program will remove all the punctuations from a String. It will check each and every character of a string inside the for loop If it founds a punctuation an empty string will be assigned to it.

In this way, every punction will be removed from our string.



13 9 6
94,240 points

Related questions

1 vote
1 answer 91 views
Problem: I was trying to remove a letter from a string by writing this python program: def removechar(p, q) : counts = p.count(q) p = list(p) while counts : p.remove(q) counts -= 1 print(p) if __name__ == '__main__' : p = "nooneisallinall" removechar(p,'n') And the program ... 'l', 'l', 'i', 'a', 'l', 'l'] How can I get the output as string after removing the specific letter. Thanks in advance.
asked May 16, 2020 samhaz 5k points
1 vote
1 answer 24 views
Problem: I am beginner in pyhton programing. I have a dictionary of string and int and that is: Dictionary = { "Hola": 65, "tart" : 32, "star" : 34, "site" : 55, "pearl" : 88 } Supose I have to remove a key from this dictionary what should I do next.
asked Mar 28, 2020 LizzyM 6.1k points
0 votes
1 answer 18 views
I want to know how to remove all punctuation from a string in python
asked Sep 25, 2020 Daniel Anderson 4k points
1 vote
1 answer 24 views
Problem: I was tring to find the length of a string in python. So I wrote a code: string = 0 for c in "popular": string+==1 print (string) which gives following error; File "ab.py", line 3 string+==1 ^ SyntaxError: invalid syntax Is this the right way to do this or there are other waysto find this out?
asked Mar 28, 2020 LizzyM 6.1k points
1 vote
1 answer 50 views
Problem: I am beginner in pyhton prgramming language, I tried to convert string array to int array using python so I wrote a code which contains- testing_list = ['4', '2', '3', '9', '5'] And my code is: testing_list = ['4', '2', '3', '9', '5 ... list is : str(testing_list) Converted list is : str(testing_list) why am I not getting the converted result and what is the way to get the acurate result?
asked Mar 29, 2020 LizzyM 6.1k points
1 vote
1 answer 705 views
Problem: I am getting the following error : error: array initializer must be an initializer list or string literal For the array; char x[80] = GetString(); Can any body explain or help?
asked Apr 2, 2020 LizzyM 6.1k points
0 votes
1 answer 33 views
I am new to python programming.. I was trying to check if a string is empty or whitespace in a code : Mystr= "" Yourstr = " " print ("This string is empty : ", end = "") if(not Yourstr): print ("Yes") print ("This string is empty : ", end = "") if(not Mystr): print ("No") It&rsquo;s output is : This string is empty : This string is empty : No Its not giving me actual result what can I do now?
asked Mar 16, 2020 LizzyM 6.1k points
0 votes
1 answer 25 views
I am new to python programming I was trying to check if a letter is uppercase in python. I wrote some code to check this statement : import string def UpperCase(s_str): for x in s_str: if x not in string.UpeerCase: return False return True But I can not get the actual ... last): File "<stdin>", line 1, in <module> NameError: name 'LoWWE' is not defined Can anyone help me to solve this thing?
asked Mar 14, 2020 LizzyM 6.1k points
1 vote
1 answer 195 views
Problem: Hello all, I am a newbie in C++ programming. I took up this project of learning with a big dream in my head. Anyway, I am struggling with a problem to figure out the solution. I was finding some basic problems from some websites to solve them. Sudden;y, I ... I explained it all to you. Now, could you please solve the problem for me? I am waiting for your answer. Thanks for your kind help.
asked May 19, 2020 adamSw 11.3k points
1 vote
2 answers 17 views
Problem: How can I deal with this problem : python remove punctuation from text file
asked Mar 19 MUHAMMAD MUNEEB 83k points