I'm new to python and am having trouble with strings. I'm getting "AttributeError: 'str' object has no attribute" but am confused as to why. I've provided some of my code so any advice would be helpful!
#Have user enter their string.
string = input("Enter a string: ")
#Find if string only contains letters and spaces
if string.isalpha():
print("Only alphabetic letters and spaces: yes")
else:
print("Only alphabetic letters and spaces: no")
#Find if string is only numeric.
if string.isdigits():
print("Only numeric digits: yes")
else:
print("Only numeric digits: no")
Aucun commentaire:
Enregistrer un commentaire