0

I'm super confused about how start and end work. I supposed this function starts to count at startth element then ends at endth element after startth element. I mean, for example, if I define start and end as 1 and 2, the element should be looked at 3. I was wrong:

a = "orange"
a.endswith("g", 0, 5)

returns True;

a = "orange"
a.endswith("g", 1, 5)

also returns True. Any explanation is appreciate!

vincent
  • 307
  • 1
  • 2
  • 11
  • 3
    `a.endswith("g", 1, 5)` is true because `a[1:5]` -> "rang" ends with `g`. Slices don't include the last index. – Mark Jun 17 '19 at 22:56
  • Possible duplicate of [Understanding slice notation](https://stackoverflow.com/questions/509211/understanding-slice-notation) – wwii Jun 17 '19 at 23:02

1 Answers1

0

I mean, for example, if I define start and end as 1 and 2, the element should be looked at 3.

The start parameter represents how many characters must be skipped from the start of the string. Ok so far. The end parameter does not represent the length from the start character, but the index of the ending character (excluded) in the source string, pretty much like slicing, as pointed out by Mark Meyer.

Attersson
  • 4,755
  • 1
  • 15
  • 29