isalnum() String Method in Python with Examples

isalnum() method returns True if the string is an alpha-numeric string otherwise it returns False.

A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.

Example 1: isalnum() String Method


message = 'welcome123'

if message.isalnum():
    print('"%s" is alphanumeric string.' %(message))
else:
    print('"%s" is not alphanumeric string.' %(message))

Output

"welcome123" is alphanumeric string.

Example 2: isalnum() String Method


message = 'welcome 123'

if message.isalnum():
    print('"%s" is alphanumeric string.' %(message))
else:
    print('"%s" is not alphanumeric string.' %(message))

Output

"welcome 123" is not alphanumeric string.

Note: this is not alphabetic since there is space in string.


Related String Methods