91 of 151 menu

The isalnum method

The isalnum method checks that the characters of a string are only letters and numbers. Nothing is passed to the method parameters. The method returns the values ​​True or False.

Syntax

string.isalnum()

Example

Let's check that the string consists only of letters and numbers:

txt = 'abcadea12' print(txt.isalnum())

Result of code execution:

True

Example

Let the line now contain other characters:

txt = '@abcadea12' print(txt.isalnum())

Result of code execution:

False

See also

  • method isalpha,
    which checks if a string contains only letters
  • method isdigit,
    which checks if a string contains only numbers
  • method isnumeric,
    which checks if a string contains only numbers
  • method isspace,
    which checks if a string contains only spaces
byenru