How can we strip punctuation at the start of a string using Python?

前端 未结 7 673
悲哀的现实
悲哀的现实 2021-01-14 11:43

I want to strip all kinds of punctuation at the start of the string using Python. My list contains strings and some of them starting with some kind of punct

7条回答
  •  北恋
    北恋 (楼主)
    2021-01-14 12:14

    Pass the characters you want to remove in lstrip and rstrip

    '..foo..'.lstrip('.').rstrip('.') == 'foo'
    

提交回复
热议问题