有各种不同的选择.每个人对你的字符串做同样的事情,但不同地处理其他字符串.
# Strip any hashes on the left.
string.lstrip('#')
# Remove hashes anywhere in the string, not necessarily just from the front.
string.replace('#', '')
# Remove only the first hash in the string.
string.replace('#', '', 1)
# Unconditionally remove the first character, no matter what it is.
string[1:]
# If the first character is a hash, remove it. Otherwise do nothing.
import re
re.sub('^#', '', string)
Run Code Online (Sandbox Code Playgroud)
(如果你不关心哪个,请使用lstrip('#').这是最自我描述的.)
| 归档时间: |
|
| 查看次数: |
2950 次 |
| 最近记录: |