Why wouldn't it be "harl"



I was curious why wouldn't print s[1:4] print "harl"?. It says Then we access a slice of "Charlie" using s[1:4]. This returns everything from the letter at position 1 up till position 4. That would include H A R L right?

 s = "Charlie"

print s[0]
# will print "C"

print s[1:4]
# will print "har"


up till 4 means position for isn't included? see slices as a loop, which uses a lesser then sign (<) so 4 is not included


Thanks, that makes sense although I wish it was practical that s[1:3] would mean H A R, but I guess I'll deal with Python as it is :slight_smile:


well, python is open source, so you could go to github, download the source code, make this change to python, compile it, and use this custom version of python on your computer. This would make your version of python incompatible with all other python versions, and it is insane lot of work, so i would just accept it as python has implanted it


Never knew that, that is cool but as you said an insane amount of work is not worth it for such an easily passable problem. Thank you for answering my question.


now you know: