Certified Associate in Python Programming (PCAP) — Question 35
Which of the following invocations are valid? (Choose two.)
Answer options
- A. ג€pythonג€.sort()
- B. sorted(ג€pythonג€)
- C. rfind(ג€pythonג€,ג€rג€)
- D. ג€pythonג€.index(ג€thג€)
Correct answer: B, D
Explanation
Option B is correct because the sorted() function can be used to sort the elements of an iterable, while option D is also correct as the index() method is valid for finding the position of a substring. Options A and C are incorrect because the sort() method cannot be called directly on a string and rfind() is not called correctly as it is a method of string objects.