从Python中的字符串中删除尾随标点符号的功能

发布于 2025-01-23 19:39:40 字数 327 浏览 3 评论 0原文

我的功能是: def remove_punctuation(字符串,标点符号),我需要按标点符号指定的所有前导和跟踪标点符号。但是,我还需要保留一个单词中的所有标点符号。 “ th,is,wo.rd!”变成“ th,is wo.rd” for def def remove_punctuation(“ th,th is,wo.rd!” ,“!。”)。然后,我需要将功能返回为字符串。

我正在尝试自我学习python,因为我的讲师对教我们的教学并没有什么帮助,因此我对这个问题陷入困境,因此,任何帮助都将不胜感激:)

My function is:
def remove_punctuation(string, punctuation) and I need to remove all leading and trailing punctuation as specified by punctuation. However, I also need to keep all punctuation that is in a word eg. "th,is, wo.rd!" becomes "th,is wo.rd" for def remove_punctuation("th,is, wo.rd!", "!.,"). I then need to return the function as a string.

I am trying to self learn python as my lecturer hasn't been all that helpful in teaching us and I have gotten stuck on this problem, so any help would be greatly appreciated :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文