• Register
1 vote
34 views

Problem:

Hello

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.

Thanks

12 7 7
15,250 points

1 Answer

1 vote

Solution:
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
print(no_punct)

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.

Thanks

 

13 9 6
94,240 points

Related questions

1 vote
1 answer 66 views
66 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 samhaz 5k points
0 votes
1 answer 5 views
5 views
I want to know how to remove all punctuation from a string in python
asked Sep 25 Daniel Anderson 4k points
1 vote
1 answer 19 views
19 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 LizzyM 6.1k points
1 vote
1 answer 15 views
15 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 LizzyM 6.1k points
1 vote
1 answer 26 views
26 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 LizzyM 6.1k points