Certified Entry-Level Python Programmer (PCEP-30-02) — Question 48
Which of the following statements can be used to return the length of the given string str?
Answer options
- A. str.size()
- B. str._len_()
- C. size(str)
- D. len(str)
Correct answer: D
Explanation
The function len(str) is the correct way to determine the length of a string in Python. The option str.size() does not exist in Python for strings, while str._len_() is not a valid method, and size(str) is not a built-in function for obtaining string lengths.