s = ''
# case 1
print(s[0])
# case 2
print(s[:1])
print(s[0:1])
In the first case I get an IndexError: string index out of range
, yet the second case is perfectly correct. I'm confused; shouldn't they be the same? In both cases we're printing the character at position 0 in the string. I can get the idea of the the Error, after-all, there are no characters in the string, but I'd expect both cases to give the same Error.
Thanks!