Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!

PythonPr's tweet image. Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!

This post is unavailable.

"python"[2:5] creates a substring of "python", starting at index 2, and stopping before 5. The indices are: 0 p 1 y 2 t <-- start 3 h 4 o 5 n <-- stop (excluded) Thus, the result is "tho" Hence, the print will output tho and that's the answer


So why did you gave C as an answer. Indexing problem?


My bad, thanks for pointing that out. It has to be B.


Go ad-free on X with Premium+ Includes access to SuperGrok.


United States Trends
Loading...

Something went wrong.


Something went wrong.