1

Im not sure why the program return true when the string contains chinese characters.

    cop = "奶helloworld茶"
    print(cop)
    print(cop.isalpha())
    print(cop.isalnum())

This gives output like this.

    奶helloworld茶
    True
    True
YYY
  • 89
  • 7

1 Answers1

2

Chinese characters are considered alphabetic in Unicode, so isalpha and isalnum will return True for them. If you don't want this, then restrict it to being ascii:

print(cop.isascii() and cop.isalpha()) # False
Aplet123
  • 33,825
  • 1
  • 29
  • 55