0

I've encountered this now and I can't understand what's going on here...:

"a//abc".lstrip("a:/")
# "bc"

Another example:

"a//bcd".lstrip("a:/")
# "bcd"

Does ":" perhaps have a special meaning for the stripping functions?

akai
  • 2,498
  • 4
  • 24
  • 46

1 Answers1

2

Because lstrip removes all characters of a set, not a substring

If you want to remove a substring from the start of a string only, I usually do:

# data = "a//abc"
# subs = "a:/"
if data.startswith(subs):
    data = data[len(subs):]
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120