Python String isalnum() Method

11-02-23 Ahmed Obaid 872 0

​The isalnum() function checks if all characters in a string are either alphanumeric or alphanumeric. If all characters in the string are alphanumeric characters, return the boolean value True. If otherwise, it returns the boolean value False.


How to formulate it like this:


string_name. isalnum()

Parameters: The isalnum() function takes no parameters.

return value:

True: If all characters in the string are either alphanumeric or alphanumeric.

True: if all characters in the string are alphanumeric characters only.

True: if all characters in the string are numeric characters only.

False: If the string contains one or more characters that are not alphanumeric.

Errors and exceptions:

If a parameter is passed to the isalnum() function, an error occurs.


Example:


# Define a variable consisting of alphanumeric characters
string = "TEL123456"
#isalnum Call and print a function
print(string.isalnum()) # returns True
# Define a variable composed of letters of the alphabet
string = "AHMED"
#isalnum Call and print a function
print(string.isalnum()) # returns True
# Define a variable consisting of numbers
string = "123456"
#isalnum Call and print a function
print(string.isalnum()) # returns True
# Define a variable consisting of letters, numbers and symbols
string = "1$"
#isalnum Call and print a function
print(string.isalnum()) # returns False

 The output will be:


True
True
True
False

 External sources:

 Built-in functions - official Python documentation

 If you have any questions or concerns, leave them in the comments



Tags


Python python data types Python String string methods python String comparison functions in Python Python String isalnum Method

Share page