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
268
"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
53
United States 趨勢
- 1. Merry Christmas 434K posts
- 2. Pro Bowl 32K posts
- 3. Kam Williams N/A
- 4. Ryan O'Hearn 1,773 posts
- 5. Ben Sasse 3,621 posts
- 6. Happy Holidays 117K posts
- 7. Louisville 5,151 posts
- 8. Bellarmine N/A
- 9. Semenyo 76.3K posts
- 10. Pirates 24.6K posts
- 11. Because Chicago 1,091 posts
- 12. Steve Rogers 22.9K posts
- 13. #Fliffmas 2,733 posts
- 14. Lookman 12.5K posts
- 15. Miller Moss N/A
- 16. Neymar 21.7K posts
- 17. Toledo 7,125 posts
- 18. Russell Brand 13.4K posts
- 19. Happy Festivus 4,855 posts
- 20. Iwobi 9,486 posts
Loading...
Something went wrong.
Something went wrong.