你查到的回答是没问题的。
isalnum()这个方法在几种数据类型中都有定义:
如果字符串是纯ascii码中的字符,那就只有字母和数字的情况下才会为True。
bytearray.isalnum()
Return true if all bytes in the sequence are alphabetical ASCII characters or ASCII decimal digits and the sequence is not empty, false otherwise. Alphabetic ASCII characters are those byte values in the sequence b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'. ASCII decimal digits are those byte values in the sequence b'0123456789'.
如果字符串还包含其他编码下的字符,那就按照你2楼中所说的那样判断。而且你看在说明文档中,判断条件也改为了“alphanumeric”
str.isalnum()
Return true if all characters in the string are alphanumeric and there is at least one character, false otherwise. A character c is alphanumeric if one of the following returns True: c.isalpha(), c.isdecimal(), c.isdigit(), or c.isnumeric().