Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
46
12
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
265
"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
48
United States 趨勢
- 1. #heatedrivalry 92K posts
- 2. Rams 79.5K posts
- 3. Seahawks 104K posts
- 4. ilya 83.1K posts
- 5. Sam Darnold 20.8K posts
- 6. Puka 53.2K posts
- 7. svetlana 7,759 posts
- 8. Stafford 22.3K posts
- 9. Al Michaels 2,905 posts
- 10. SCOTT HUNTER 12.5K posts
- 11. #PowerForce 1,503 posts
- 12. Rose 173K posts
- 13. Ben Shapiro 48.1K posts
- 14. #zzzSpecialProgram 6,711 posts
- 15. jacob tierney 6,132 posts
- 16. connor storrie 17.9K posts
- 17. #TSTheEndOfAnEra 11.1K posts
- 18. McVay 8,335 posts
- 19. #TNFonPrime 6,828 posts
- 20. Portuguese 31K posts
Loading...
Something went wrong.
Something went wrong.