I am writing a function to explain the first charachter of a string. If it is a capital it should return ‘upper’, if a lower then ‘lower’, if a digit then ‘digit’ else ‘other’
def solution(s):
c = s[0]
if c.isupper() == True:
return "upper"
The above is not returning true for "Hello"
How to go ahead?
>Solution :
This works:
def solution(s):
c = s[0]
try:
int(c)
return "digit"
except ValueError:
if c.isupper() == True:
return "upper"
elif c.islower() == True:
return "lower"
else:
return "other"