Remove the first character of a string

后端 未结 5 604
萌比男神i
萌比男神i 2020-12-07 21:38

I would like to remove the first character of a string.

For example, my string starts with a : and I want to remove that only. There are several occurre

5条回答
  •  没有蜡笔的小新
    2020-12-07 21:57

    Depending on the structure of the string, you can use lstrip:

    str = str.lstrip(':')
    

    But this would remove all colons at the beginning, i.e. if you have ::foo, the result would be foo. But this function is helpful if you also have strings that do not start with a colon and you don't want to remove the first character then.

提交回复
热议问题