A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/python-string-isalnum-method/ below:

Python String isalnum() Method - GeeksforGeeks

Python String isalnum() Method

Last Updated : 21 Apr, 2025

The isalnum() method is a string function in Python that checks if all characters in the given string are alphanumeric. If every character is either a letter or a number, isalnum() returns True. Otherwise, it returns False.

For Example:

Python
s = "Python123"
res = s.isalnum()
print(res)

Explanation: In this example, s contains only letters and numbers, so isalnum() returns True.

Syntax

s.isalnum()

Parameters:

Return Type:

Examples of isalnum() Method Example 1: Empty String

An empty string will return False since there are no alphanumeric characters.

Python
s = ""
res = s.isalnum()
print(res)
Example 2: String with Only Digits

The method will also return True for a string with only numeric characters.

Python
s = "123456"
res = s.isalnum()
print(res)
Example 3: String with Only Letters

Similarly, a string containing only letters will return True.

Python
s = "Python"
res = s.isalnum()
print(res)
Example 4: String with Non-Alphanumeric Characters

If the string contains a space and an exclamation mark, so isalnum() returns False.

Python
s = "Python 123!"
res = s.isalnum()
print(res)

Explanation: in this code, isalnum() returns False because the string s contains space " " and exclamation mark (!) which are neither numbers nor alphabets.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4