PCEP-30-02 practice question 21 of 35
isalnum() checks if a string contains only letters and digits, and this is:
Full set: 548 questionsDomain Data Collections – Tuples, Dictionaries, Lists, and Strings
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.
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.
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.
Keep practicing
Take the free PCEP-30-02 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other PCEP-30-02 practice questions
- Question 1The following list is given:
- Question 2What is the output of the following code? num = 10 while num >= 0: num -= 2 print(num)
- Question 4We need to check if at least one element of the iterable object evaluates to the truth. W…
- Question 5This question is a tricky one. What is the result of the following code snippet? numbers …
- Question 8What is the purpose of the continue statement in Python?
- Question 11We need to check if all elements of the iterable object evaluate to the truth. What built…
