0

I am converting python code to java. It appears that when a python string is empty, a statement like this

mystring[-4:]

is perfectly fine. no exception occurs at all.

Is this right? I am from a java background. I just find this hard to believe.

Mazdak
  • 105,000
  • 18
  • 159
  • 188
bhomass
  • 3,414
  • 8
  • 45
  • 75
  • See http://stackoverflow.com/questions/9490058/why-substring-slicing-index-out-of-range-works-in-python – rosshamish Apr 17 '15 at 19:21
  • @rosshamish Flag as duplicate if you see striking resemblance amongst 2 questions. – Bhargav Rao Apr 17 '15 at 19:22
  • Straight quote from the [docs](https://docs.python.org/2/tutorial/introduction.html#strings) *out of range slice indexes are handled gracefully when used for slicing* and do not result in Exceptions – Bhargav Rao Apr 17 '15 at 19:23
  • @BhargavRao Thanks for the tip, I was actually wondering how to mark as duplicate, hadn't done it before. OP: The question I linked explains this pretty well, take a look. – rosshamish Apr 17 '15 at 19:24
  • thanks. takes some getting use to. – bhomass Apr 17 '15 at 21:45

0 Answers0