Reputation: 89
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
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