python - 返回 Python 字符串中第一个非空白字符的最低索引

标签 python string string-matching

在 Python 中执行此操作的最短方法是什么?

string = "   xyz"

必须返回 index = 3

最佳答案

>>> s = "   xyz"
>>> len(s) - len(s.lstrip())
3

关于python - 返回 Python 字符串中第一个非空白字符的最低索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2378962/

相关文章:

r - 删除数据框中引用另一个 (R) 中不存在的 ID 的行?

python - 用于捕获部分字符串的正则表达式

string - FSharp.Core.String 中的 concat 与 System.String 中的 Concat

string - Clojure:在字符串中插入字符的惯用方法

python - 动态查找两个字符串之间的多个空格

javascript - 如果字符串包含完全匹配,则使用 javascript 返回 true

python - 如何使用tensor.item()? IndexError : invalid index of a 0-dim tensor. 使用tensor.item()将0维张量转换为Python数字

python - Python 中的 Swift Optionals(或 Haskell 的 Maybe)?

php - python 2.7 : How to build getter/setter functions to access class attributes without inheritance?

java - 两个内容相同的字符串会存储在同一个内存位置吗?