Most Pythonic was to strip all non-alphanumeric leading characters from string

前端 未结 3 820
[愿得一人]
[愿得一人] 2021-01-29 11:52

For example

!@#123myname --> myname
!@#yourname!@#123 --> yourname!@#123

There are plenty of S.O. examples of \"most pythonic ways of re

3条回答
  •  天涯浪人
    2021-01-29 12:49

    Just use str.lstrip.

    It takes a string containing the characters to remove from the left side of the string, and will remove those characters regardless of the order in which they appear. For example:

    s = "!@#yourname!@#"
    print s.lstrip('@!#') # yourname!@#
    

提交回复
热议问题