Strings and Lists - string slicing, immutability, string methods, list operations, mutability, cloning, list parameters - Question Bank
1. When `my_list = [1, 2, 3, 4, 5]` and `new_list = my_list`, what kind of relationship is established between `my_list` and `new_list`?
2. What is the slicing syntax `[start:stop:step]` used for in Python?
3. Which string method checks if a string ends with a specified suffix?
4. What is the consequence of modifying a list passed as an argument to a function without creating a copy?
5. If `my_list = [1, 2, 3]` is passed to a function `def modify(lst): lst.append(4)`, what will be the value of `my_list` after calling `modify(my_list)`?
6. What does `my_string.partition(' ')` return for `my_string = 'hello world'`?
7. Which string method returns a list of all the words in a string, using whitespace as the delimiter?
8. What is the difference between `sorted(my_list)` and `my_list.sort()`?
9. Which list method sorts the list in place?
10. If `my_list = ['a', 'b', 'c']`, what is the result of `my_list * 2`?
11. What is the purpose of `del my_list[index]`?
12. Which string method converts the first character of each word in a string to uppercase?
13. What does `my_string.count('a')` return for `my_string = 'banana'`?
14. When passing a list to a function, the function receives a reference to the original list object. This is often referred to as:
15. How can you create a deep copy of `my_list`?
16. Which module in Python provides functions for creating deep copies?
17. What is a 'deep copy' of a list?
18. If `list1 = [1, 2]` and `list2 = [3, 4]`, what is the result of `list1.extend(list2)`?
19. What does the `extend()` list method do?
20. If `my_list = [10, 20, 30]` and you execute `my_list.append(40)`, what is the final state of `my_list`?
21. Which string method returns a copy of the string with its first character capitalized?
22. Consider `'-'.join(['a', 'b', 'c'])`. What is the result?
23. What does the `join()` string method do?
24. If `my_list = [1, 2, 3, 4, 5]` and `new_list = my_list[1:4]`, what is `new_list`?
25. Which list operation returns a new list containing elements from a specified range?
26. What will `my_string.replace('l', 'X')` return if `my_string = 'hello world'`?
27. Which string method checks if all characters in the string are alphanumeric?
28. What is the term for passing a list to a function such that the function operates on the original list object?
29. When a list is passed as an argument to a function, what happens if the function modifies the list?
30. What does slicing a list, like `new_list = old_list[:]`, achieve?
31. What is a potential pitfall of assigning one list variable to another using `list2 = list1`?
32. Which method is commonly used for shallow cloning of a list?
33. What is the term for creating an independent copy of a list?
34. If `list1 = [1, 2]` and `list2 = [3, 4]`, what is the result of `list1 + list2`?
35. Which list operation is used to combine two lists?
36. What does `my_list.pop(2)` do if `my_list = [10, 20, 30, 40]`?
37. Which list method is used to remove the first occurrence of a specific value from the list?
38. If `my_list = [1, 2, 3]`, what will `my_list.insert(1, 10)` change the list to?
39. Which operation is used to add an element to the end of a list?
40. What is the primary characteristic of a list in Python that allows modification after creation?
41. Which string method removes whitespace from the beginning and end of a string?
42. What is the difference between `find()` and `index()` string methods?
43. Which string method is used to find the first occurrence of a substring within another string?
44. What does the `split()` method do to a string by default?
45. Which string method is used to convert all characters in a string to uppercase?
46. What is the effect of `my_string[::-1]` on a string `my_string`?
47. What does the slice `my_string[3:]` represent for `my_string = 'Programming'`?
48. If `my_string = 'Python'`, what will `my_string[0:2]` return?
49. Which operation is used to access a portion of a string in Python?
50. What is the primary characteristic of a string in Python that prevents direct modification after creation?