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 79.2K posts
- 2. Miami 79.2K posts
- 3. Marcel Reed 2,325 posts
- 4. Carson Beck 3,097 posts
- 5. Dawson 6,344 posts
- 6. Isak 30.8K posts
- 7. Romero 18.6K posts
- 8. Toney 3,671 posts
- 9. Liverpool 67K posts
- 10. St. John 5,878 posts
- 11. #CFP2025 N/A
- 12. Lowe 9,154 posts
- 13. Clinton 465K posts
- 14. Jayden Quaintance 1,831 posts
- 15. Carter Davis N/A
- 16. Wirtz 29.7K posts
- 17. #TOTLIV 19.6K posts
- 18. Fletcher 5,728 posts
- 19. Tottenham 31.2K posts
- 20. Cristobal 2,655 posts
Loading...
Something went wrong.
Something went wrong.