Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 95
    The beginners should learn the pythonic way when moving to python, not stick to other language habits Commented May 29, 2013 at 13:58
  • 3
    And just for completeness, Java is like Python in that the String.substring() method takes start and one-past-end. This one just bit me hard, I had assumed it was length like every other substring function in the world. Commented Jan 10, 2019 at 13:34
  • 15
    A (probably) more pythonic way to do that is s[beginning:][:length] Commented Mar 12, 2019 at 22:47
  • 2
    As someone who began with Python instead of [dirty word]-languages like PHP, I think Python is much more simple and intuitive with its string[beginning:end]. Length generally isn't relevant. Commented Oct 9, 2019 at 9:00
  • 2
    @PhilHibbs "Like every other substring function" is rather too strong a statement, since there are at least two other common ways to interpret substring arguments. One is (start, length) and the other is (start, end). Python's (start, end+1) is admittedly unusual, but fits well with the way other things in Python work. Commented Jan 29, 2022 at 22:16

lang-py