Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is isalnum() in Python?

Mahnoor Zaheer

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The isalnum() method is a boolean function in Python that tells whether a string contains only alphanumeric, alphabetic, or numeric characters.

Syntax

The syntax of the isalnum() method is:

string.isalnum()
The syntax of the isalnum() method in Python

Parameters and return value

isalnum() takes no parameters. The function returns True if the string only contains alphanumeric, alphabetical, or numeric characters; otherwise, it returns False.

Code

In the code below, isalnum() returns True for alphanumeric, numeric, and alphabetical strings, and returns False for strings with whitespaces and punctuation marks.

# contains alphanumeric characters
alphanum = "abc345ch7"
print(alphanum.isalnum())
# contains alphabets only
alpha = "abcdef"
print(alpha.isalnum())
# contains numbers only
num = "12345"
print(num.isalnum())
# contains spaces and punction marks along with alphabets and numbers
punctuation_space = "$1#2 @3abc 4,5"
print(punctuation_space.isalnum())
The code example of the isalnum() method in Python

RELATED TAGS

python
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring