2019-01-23 13:29:58 364浏览
今天扣丁学堂Python培训老师给大家分享一篇关于python3去掉string中的标点符号方法详解,首先python去掉字符串中的标点符号的方法,大多是基于python2的,不适用python3,调整后代码如下:
lower_case_documents = ['Hello, how are you!','Win money, win from home.','Call me now.','Hello, Call hello you tomorrow?'] sans_punctuation_documents = [] import string for i in lower_case_documents: # TODO trantab = str.maketrans({key: None for key in string.punctuation}) j = i.translate(trantab) sans_punctuation_documents.append(j) print(sans_punctuation_documents) ['hello how are you', 'win money win from home', 'call me now', 'hello call hello you tomorrow']
以上就是关于扣丁学堂Python培训解析如何去掉string中的标点符号方法的全部内容了,希望对大家的学习有所帮助,扣丁学堂IT职业在线学习教育平台为您提供权威的Python视频教程课程,还有扣丁学堂老师精心推出的Python视频直播课定能让你快速掌握Python从入门到精通开发实战技能。扣丁学堂Python技术交流群:279521237。
【关注微信公众号获取更多学习资料】