Why wouldn't it be "harl"


#1



https://www.codecademy.com/courses/python-beginner-2W5v7/1/4?curriculum_id=4f89dab3d788890003000096#


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"


#2

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


#3

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:


#4

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


#5

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.


#6

now you know:
https://www.python.org/downloads/source/


#7