Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
46
11
115
19
11K
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 Trends
- 1. Bama 23.1K posts
- 2. Ryan Williams 2,569 posts
- 3. Oklahoma 42K posts
- 4. Mateer 7,428 posts
- 5. Woodley 12.9K posts
- 6. Epstein 1M posts
- 7. Anderson Silva 8,434 posts
- 8. #CFBPlayoff 9,802 posts
- 9. Clinton 181K posts
- 10. #JakeJoshua 24.9K posts
- 11. #SmackDown 15.6K posts
- 12. Ty Simpson 2,528 posts
- 13. #RollTide 7,354 posts
- 14. DeBoer 5,723 posts
- 15. Chris Finch 1,246 posts
- 16. #OPLive 1,419 posts
- 17. Sixers 4,933 posts
- 18. Maxey 3,343 posts
- 19. Kay Adams N/A
- 20. VJ Edgecombe 1,348 posts
Loading...
Something went wrong.
Something went wrong.