PCEP-30-02 practice question 21 of 35

isalnum() checks if a string contains only letters and digits, and this is:

Full set: 548 questions

Domain Data Collections – Tuples, Dictionaries, Lists, and Strings

Answer options
A: A method Correct answer
B: A module
C: A function
Correct Answer:
A. A method
Explanation

In Python, isalnum() is a built-in string method. A method is a function that is associated with an object. Since isalnum() is called on a string object using dot notation (e.g., 'Python123'.isalnum()), it is classified as a method of the str class. It operates on the data contained within the string instance it is called on, returning True if all characters are alphanumeric and the string is not empty, and False otherwise. This is a core concept of Python's object-oriented programming model.

Why Incorrect

B. A module: A module is a file containing Python definitions and statements that can be imported. isalnum() is a built-in part of the str type, not a separate module.
C. A function: While methods are technically functions, in Python's specific terminology, a "function" usually refers to a standalone callable (e.g., len(), print()). "Method" is the more precise term for a function bound to an object.

References

1. Python Software Foundation. (2024). Built-in Types — Python 3.12.3 documentation.

Section: Text Sequence Type — str, String Methods.

Details: The official Python documentation explicitly categorizes isalnum() under the "String Methods" section, stating: "str.isalnum() Return True if all characters in the string are alphanumeric and there is at least one character, False otherwise." This confirms its classification as a method.

2. Guttag, J. V. (2016). 6.0001 Introduction to Computer Science and Programming in Python, Fall 2016. Massachusetts Institute of Technology: MIT OpenCourseWare.

Section: Lecture 4: Strings, Tuples, Ranges, Lists.

Details: The course materials distinguish between functions that take an object as an argument (e.g., len(s)) and operations performed on an object using dot notation (e.g., s.find('a')), which are referred to as "methods". This aligns with isalnum() being a method.

3. Python Institute. (2023). PCEP-30-02 – Exam Syllabus.

Section: 2.3 Basic data types, literals, variables, and basic I/O operations.

Details: The syllabus lists "methods: the .upper() and .lower() methods" as a key topic. This demonstrates that the PCEP exam requires candidates to identify and understand that functions called on string objects using dot notation are termed "methods". isalnum() follows the exact same syntax and principle.

Scroll to Top