I am trying to write a code that compares two strings and return the string if a match is found with the case sensitive condition except for the capital. That’s the function I have wrote and I have learned that == is pretty good for comparing case sensitively. However it still prints January for the last test line which is not expected. So can you help me out please?
months = ['January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December']
def valid_month(month):
for x in months:
if x==month.capitalize() :
print x
Test codes:
valid_month("january")
valid_month("January")
valid_month("foo")
valid_month("")
valid_month("jaNuary")
How about this:
This will test equality with case sensitivity – except for the first character.