How to remove punctuation marks from a string in Python 3.x using .translate()?

前端 未结 5 1043
我在风中等你
我在风中等你 2020-12-02 06:16

I want to remove all punctuation marks from a text file using .translate() method. It seems to work well under Python 2.x but under Python 3.4 it doesn\'t seem to do anythin

5条回答
  •  感动是毒
    2020-12-02 07:05

    In python3.x ,it can be done using :

    import string
    #make translator object
    translator=str.maketrans('','',string.punctuation)
    string_name=string_name.translate(translator)
    

提交回复
热议问题