YYY
YYY

Reputation: 89

How does isalnum() and isalpha works in python? Returning true when chinese is included

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

Upvotes: 1

Views: 1052

Answers (1)

Aplet123
Aplet123

Reputation: 35540

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

Upvotes: 2

Related Questions