Friday, September 11, 2026

Python Slicing

 Python Slicing:


1. What is the output? s = "Python" print(s[0:3])

   A. 'Pyt'

   B. 'Pyth'

   C. 'Python'

   D. 'yth'


2. What is the output? s = "Python" print(s[2:5])

   A. 'yth'

   B. 'hon'

   C. 'thon'

   D. 'tho'


3. What is the output? nums = [10, 20, 30, 40, 50] print(nums[-3:])

   A. [40, 50]

   B. [30, 40]

   C. [20, 30, 40]

   D. [30, 40, 50]


4. What is the output? s = "abcdef" print(s[::2])

   A. 'ace'

   B. 'fed'

   C. 'abcd'

   D. 'bdf'


5. What is the output? s = "Python" print(s[::-1])

   A. 'nothP'

   B. 'Python'

   C. 'Pnohty'

   D. 'nohtyP'


6. What is the output? nums = [0, 1, 2, 3, 4, 5] print(nums[1:5:2])

   A. [0, 2, 4]

   B. [2, 4]

   C. [1, 3]

   D. [1, 3, 5]


7. What is the output? s = "Python" print(s[:4])

   A. 'ytho'

   B. 'Pytho'

   C. 'Python'

   D. 'Pyth'


8. What is the output? s = "Python" print(s[2:])

   A. 'tho'

   B. 'Python'

   C. 'thon'

   D. 'ython'


9. What is the output? s = "abcdef" print(s[1:6:2])

   A. 'bcdef'

   B. 'ace'

   C. 'bde'

   D. 'bdf'


10. What is the output? s = "abcdef" print(s[-1])

   A. 'f'

   B. 'e'

   C. 'd'

   D. 'a'


11. What is the output? s = "Python" print(s[-4:-1])

   A. 'yth'

   B. 'hon'

   C. 'tho'

   D. 'ytho'


12. What is the output? nums = [1, 2, 3, 4, 5, 6] print(nums[::3])

   A. [1, 4]

   B. [2, 5]

   C. [1, 4, 6]

   D. [1, 3, 5]


13. What is the output? s = "abcdef" print(s[5:1:-1])

   A. 'fedc'

   B. 'edcb'

   C. 'fed'

   D. 'fecd'


14. What is the output? s = "abcdef" print(s[::-2])

   A. 'fdb'

   B. 'bdf'

   C. 'eca'

   D. 'fed'


15. What is the output? s = "Python" print(s[1:5:3])

   A. 'yth'

   B. 'yt'

   C. 'to'

   D. 'yo'


16. What is the output? s = "Python" print(s[::])

   A. 'ython'

   B. 'Pyth'

   C. 'Python'

   D. 'nohtyP'


17. What is the output? nums = [10, 20, 30, 40, 50] print(nums[1:-1])

   A. [30, 40]

   B. [20, 30, 40]

   C. [20, 30, 40, 50]

   D. [10, 20, 30, 40]


18. What is the output? s = "abcdef" print(s[4:1:-1])

   A. 'fed'

   B. 'cde'

   C. 'edc'

   D. 'edcb'


19. What is the output? s = "abcdefgh" print(s[2:7:2])

   A. 'bdf'

   B. 'ceg'

   C. 'cdefg'

   D. 'ce'


20. What is the output? s = "Python" print(s[-5:-2])

   A. 'tho'

   B. 'yth'

   C. 'Pyt'

   D. 'ytho'