从Python中的字符串中删除尾随标点符号的功能
我的功能是: 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论