Python3 String Isalnum
# Python3.x Python3 isalnum() Method
[ Python3 Strings](#)
* * *
## Description
The `isalnum()` method is used to check whether a string consists of only alphanumeric characters, meaning all characters in the string are letters or numbers.
* **Empty String**: If the string is empty (length 0), it returns `False`, because an empty string contains no letters or numbers.
* **Case Sensitivity**: The `isalnum()` method is case-sensitive, meaning only characters that are letters or numbers are considered valid.
* **Special Characters**: Special characters (such as punctuation, spaces, special symbols, etc.) are not considered letters or numbers.
## Syntax
The syntax for the `isalnum()` method is:
str.isalnum()
## Parameters
* None.
## Return Value
Returns `True` if the string has at least one character and all characters are alphanumeric; otherwise, returns `False`.
## Examples
The following examples demonstrate the use of the `isalnum()` method:
## Example (Python 2.0+)
#!/usr/bin/python3 str = "tutorial2016"# String has no spaces print(str.isalnum())str = "www."print(str.isalnum())
The output of the above example is:
TrueFalse
More examples:
## Example
# Example 1: String containing letters and numbers
print("abc123".isalnum())# Output: True
# Example 2: String containing a space
print("abc 123".isalnum())# Output: False
# Example 3: String containing a special character
print("abc#123".isalnum())# Output: False
# Example 4: Empty string
print("".isalnum())# Output: False
# Example 5: String containing only numbers
print("123456".isalnum())# Output: True
# Example 6: String containing only letters
print("abcdef".isalnum())# Output: True
# Example 7: String containing an underscore (not a letter or number)
print("abc_def".isalnum())# Output: False
* * Python3 Strings](#)
YouTip