PCAP-31-03 practice question 15 of 25
Which of the following invocations are valid? (Select two answers)
Full set: 147 questionssorted(iterable) is a built-in that accepts a string and returns a list of its characters, so sorted("python") is valid. str.index(sub[, start[, end]]) is a legal method invocation; "python".index("th") returns 2. The other two calls either lack the required object context or reference a non-existent method.
A. rfind is a string method (or string.rfind in the string module); calling it as a standalone function without import/object raises NameError.
C. str objects have no sort() method; invoking it raises AttributeError.
1. Python Documentation, Library Reference 3.12 – §4.7 “Built-in Types”: str.index description.
2. Python Documentation, Library Reference 3.12 – “Built-in Functions”, entry for sorted().
3. Python Documentation, Library Reference 3.12 – 4.7 “str methods”, entry for rfind (object method).
4. University of Michigan “Python 3 Programming” course notes, Week 4, section “Sorting”.
Keep practicing
Take the free PCAP-31-03 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other PCAP-31-03 practice questions
- Question 3How many elements will the list2 list contain after execution of the following snippet? l…
- Question 6Select the valid fun () invocations: (select two answers) def fun (a, b=0): return a*b
- Question 7Is it possible to safely check if a class object has a certain attribute0
- Question 10Which of the equations are True? (Select two answers)
- Question 13Which of the following lambda function definitions are correct? (Select two answers)
- Question 16Which of the following words can be used as a variable name? (Select two valid names)
