Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
46
11
114
19
11천
Answer: B Solution: This is an application of slicing in python. As you know, [] is used for indexing, ie, picking out one item from a list or string. But there is more to it. [] can also be used for slicing, ie, to extract multiple items. Let's see how it works +
1
0
2
0
266
"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 index 3 h 4 o 5 n <-- stop index (excluded) Thus, the result is "tho" Hence, the print will output tho and that's the answer
0
0
0
0
50
United States 트렌드
- 1. Miami 105K posts
- 2. Tulane 13.8K posts
- 3. Marcel Reed 6,378 posts
- 4. Ole Miss 10.9K posts
- 5. Michael Irvin 4,965 posts
- 6. Shipley N/A
- 7. Notre Dame 32.6K posts
- 8. Aggies 6,848 posts
- 9. Fletcher 9,971 posts
- 10. Toney 8,295 posts
- 11. Carson Beck 3,998 posts
- 12. #CFPplayoff N/A
- 13. Go Birds 7,446 posts
- 14. Everton 51.4K posts
- 15. Clinton 486K posts
- 16. Odegaard 7,775 posts
- 17. The U 474K posts
- 18. Elko 2,002 posts
- 19. Austin Simmons N/A
- 20. #EVEARS 7,772 posts
Loading...
Something went wrong.
Something went wrong.