How to check if a string contains only letters and digits in Python

1 Answer

0 votes
s = "abcABC123"
if s.isalnum():
    print("yes")
else:
    print("no")


s = "abc-ABC 123"
if s.isalnum():
    print("yes")
else:
    print("no")


'''
run:
 
yes
no

'''

 



answered Nov 17, 2018 by avibootz
...