समस्या विवरण
स्ट्रिंग से सभी विराम चिह्न हटाने का सबसे तेज़ तरीका str.translate() का उपयोग करना है।
उदाहरण
import string
s = "string. With. Punctuation?"
print(s.translate(None, string.punctuation))
आउटपुट
string With Punctuation
उदाहरण
यदि आप अधिक पठनीय समाधान चाहते हैं, तो आप सेट पर स्पष्ट रूप से पुनरावृति कर सकते हैं और लूप में सभी विराम चिह्नों को अनदेखा कर सकते हैं।
s = "string. With. Punctuation?"
exclude = set(string.punctuation)
s = ''.join(ch for ch in s if ch not in exclude)
print(s)
आउटपुट
string With Punctuation