try this! it worked for me even if I input negative numbers.
def length(s):
return len(s)
s = input("Enter the String: ")
try:
if (type(int(s)))==int :
print("You input an integer")
except ValueError:
print("it is a string with length " + str(length(s)))