Join Regular Classroom : Visit ClassroomTech

Python String – isalnum() method

It is a method in python string that checks if all the characters in the given string are either alphabets (a-z, A-Z) or numbers (0-9) or both. It returns True if satisfies the condition else returns False.

Syntax:

string.isalnum()

Note:

space is considered a special character in python.

Example 1:

s = “CodeWindow
x = s.isalnum()
print(x)

Output:

True

Explanation:

Here the string has all the characters as alphabets.

Example 2:

s = “CodeWindow123
x = s.isalnum()
print(x)
Output:

True

Explanation:

Here the string contains both alphabets and numbers. Hence it returned True.

Example 3:

s = “123
x = s.isalnum()
print(x)

Output:

True

Explanation:

Here the string has all the characters as numbers. Hence returned True.

Example 4:

s = “Code Window
x = s.isalnum()
print(x)

Output:

False

Explanation:

Here the string has a special character in between i.e. Space. Hence returned False.

You Missed
Also Checkout