Slicing
1. After the assignment x = 'Very Naughty Boy', which of the following assigns 'N' to the variable y?
(a) y = x[-10]
(b) y = x[-12]
(c) y = x[5]
(d) y = x[6]
(e) More than one of the above is correct.
2. After the assignment x = 'Very Naughty Boy', which of the following assigns 'Naug' to the variable y?
(a) y = x[5:8]
(b) y = x[5:9]
(c) y = x[6:9]
(d) y = x[6:10]
(e) More than one of the above is correct.
3. After the assignment x = 'Very Naughty Boy', which of the following assigns 'hty' to the variable y?
(a) y = x[-8:-5]
(b) y = x[-8:-4]
(c) y = x[-7:-5]
(d) y = x[-7:-4]
(e) More than one of the above is correct.
4. After the assignment x = 'Very Naughty Boy', which of the following assigns 'B y' to the variable y?
(a) y = x[-4:-5:-1]
(b) y = x[-4:-6:-1]
(c) y = x[-3:-5:-1]
(d) y = x[-3:-6:-1]
(e) More than one of the above is correct.
5. After the assignment x = 'Very Naughty Boy', which of the following assigns 'N' to the variable y?
(a) y = x[-10]
(b) y = x[-11]
(c) y = x[-12]
(d) y = x[6]
(e) More than one of the above is correct.
6. After the assignment x = 'Very Naughty Boy', which of the following assigns 'augh' to the variable y?
(a) y = x[5:8]
(b) y = x[5:9]
(c) y = x[6:9]
(d) y = x[6:10]
(e) None of the above are correct.
7. After the assignment x = 'Very Naughty Boy', which of the following assigns 'ght' to the variable y?
(a) y = x[-8:-5]
(b) y = x[-8:-4]
(c) y = x[-7:-5]
(d) y = x[-7:-4]
(e) None of the above are correct.
8. After the assignment x = 'Very Naughty Boy', which of the following assigns 'uaN' to the variable y?
(a) y = x[-9:-12:-1]
(b) y = x[4:6:-1]
(c) y = x[6:4:-1]
(d) y = x[4:6:1]
(e) More than one of the above is correct.
9. After the assignment x = 'Quick brown fox', which of the following assigns 'w' to the variable y?
(a) y = x[10]
(b) y = x[11]
(c) y = x[-6]
(d) y = x[-7]
(e) More than one of the above is correct.
10. After the assignment x = 'Quick brown fox', which of the following assigns 'fox' to the variable y?
(a) y = x[12:14]
(b) y = x[13:15]
(c) y = x[13:16]
(d) y = x[12:15]
(e) More than one of the above is correct.
11. After the assignment x = 'Quick brown fox', which of the following assigns 'fox' to the variable y?
(a) y = x[-3:]
(b) y = x[-3:-1]
(c) y = x[-4:]
(d) y = x[-4:-1]
(e) More than one of the above is correct.
12. After the assignment x = 'Quick brown fox', which of the following assigns 'nwo' to the variable y?
(a) y = x[-5:-8:-1]
(b) y = x[-6:-9:-1]
(c) y = x[-5:-8:1]
(d) y = x[-6:-9:1]
(e) More than one of the above is correct.
13. After the assignment x = 'Sample text', which of the following assigns 'l' to the variable y?
(a) y = x[5]
(b) y = x[4:5]
(c) y = x[-6]
(d) y = x[6]
(e) More than one of the above is correct.
14. After the assignment x = 'Sample text', which of the following assigns 'text' to the variable y?
(a) y = x[8:11]
(b) y = x[7:11]
(c) y = x[8:]
(d) y = x[7:]
(e) More than one of the above is correct.
15. After the assignment x = 'Sample text', which of the following assigns 'ple' to the variable y?
(a) y = x[-8:-5]
(b) y = x[-8:-6]
(c) y = x[-7:-4]
(d) y = x[-7:-5]
(e) More than one of the above is correct.
16. After the assignment x = 'Sample text', which of the following assigns 'pet' to the variable y?
(a) y = x[-8:-4:2]
(b) y = x[-8:-3:2]
(c) y = x[-7:-4:2]
(d) y = x[-7:-3:2]
(e) More than one of the above is correct.
17. After the assignment x = 'Dogs and cats', which of the following assigns 'n' to the variable y?
(a) y = x[6]
(b) y = x[7]
(c) y = x[-8]
(d) y = x[7:8]
(e) More than one of the above is correct.
18. After the assignment x = 'Dogs and cats', which of the following assigns 'and' to the variable y?
(a) y = x[6:8]
(b) y = x[6:9]
(c) y = x[-8:-5]
(d) y = x[-8:-6]
(e) None of the above.
19. After the assignment x = 'Critical mass', which of the following assigns 'cit' to the variable y?
(a) y = x[5:2:-1]
(b) y = x[-8:-11]
(c) y = x[-8:-11:-1]
(d) y = x[5:2]
(e) More than one of the above is correct.
20. After the assignment x = 'Critical mass', which of the following assigns 'tam ' to the variable y?
(a) y = x[3:10:3]
(b) y = x[3:3:10]
(c) y = x[4:10:3]
(d) y = x[4:3:9]
(e) More than one of the above is correct.
21. After the assignment x = 'Just in time', which of the following statements assigns 'st' to y?
(a) y = x[3:5]
(b) y = x[2:4]
(c) y = x[-7:-9]
(d) y = x[-10:-8]
(e) More than one of the above is correct.
22. What does the following expression evaluate to?
('abcdef' + 'ghi')[2:6:2]
(a) 'bd'
(b) 'ce'
(c) 'bdf'
(d) 'ceg'
(e) None of the above
23. After the assignment s1 = "Monty Python", which of the following statements assigns 'Py' to s2?
(a) s2 = s1[6:2]
(b) s2 = s1[-6:-2]
(c) s2 = s1[6:7]
(d) s2 = s1[6:8]
(e) More than one of the above is correct.
24. What does the following expression evaluate to?
('abc' + 'def' + 'ghi')[2]
(a) 'c'
(b) 'b'
(c) 'ghi'
(d) 'def'
(e) Error
25. After the assignment s1 = "Programming" + " is " + "Fun", which of the following statements assigns 'is' to s2?
(a) s2 = s1[1]
(b) s2 = s1[-6:-4]
(c) s2 = s1[12:13]
(d) s2 = s1[12:14]
(e) More than one of the above is correct.
26. What is the value of s4 after the following statements are evaluated?
s1 = "Hello"
s2 = "World"
s3 = "Ni Hao"
s3 = s1
s3 = "Hi"
s4 = s1 + s2
(a) "HiWorld"
(b) "HelloWorld"
(c) "Ni HaoWorld"
(d) Error
27. After the assignment s1 = "Silver lining", which of the following statements assigns 'r l' to s2?
(a) s2 = s1[5:7]
(b) s2 = s1[5:8]
(c) s2 = s1[-8:-6]
(d) s2 = s1[-6:-8]
(e) More than one of the above is correct.
28. After the assignment s1 = "Silver lining", what will the value of s2 be after the following command is entered?
s2 = s1[::-2]
(a) 'gii elS'
(b) 'ngSilver lini'
(c) 'gSilver linin'
(d) None of the above
29. After the assignment s1 = "Ode to Programming", which of the following statements assigns 'rog' to s2?
(a) s2 = s1[8:11]
(b) s2 = s1[8:10]
(c) s2 = s1[-7:-10]
(d) s2 = s1[-10:-7]
(e) More than one of the other options are correct
30. Given the assignment s1 = "Ode to Programming", what will the value of s2 be after the following command is entered?
s2 = s1[3:11:4]
(a) s2 = 'e '
(b) s2 = ' Pr'
(c) s2 = ' P'
(d) None of the other choices are correct
31. After the assignment s1 = "Never give up", which of the following statements assigns 'r g' to s2?
(a) s2 = s1[4:7]
(b) s2 = s1[4:8]
(c) s2 = s1[-9:-7]
(d) s2 = s1[-9:-6]
(e) More than one of the other choices are correct
32. After the assignment s1 = "Never give up", what will the value of y be after the following command is entered?
s2 = s1[6::-2]
(a) s2 = 'p v'
(b) s2 = 'give '
(c) s2 = 'grvN'
(d) None of the other choices are correct