Tom*_*Tom 2 python string removing-whitespace
嗨,我有python中的字符串列表
[" 0", " 1", " 2"]
Run Code Online (Sandbox Code Playgroud)
我想从其中一个的开头删除空格.
我该怎么做?
如果要从所有这些空格中删除空格,可以使用
a = [" 0", " 1", " 2"]
b = [s.lstrip() for s in a]
Run Code Online (Sandbox Code Playgroud)
如果你真的只想剥离其中一个,请使用
a[i] = a[i].lstrip()
Run Code Online (Sandbox Code Playgroud)
i你想要剥离的索引在哪里.
| 归档时间: |
|
| 查看次数: |
5137 次 |
| 最近记录: |