Thursday, 15 August 2013

Python 2.7: instead of string "True" or "False" return a Boolean

Python 2.7: instead of string "True" or "False" return a Boolean

I have a small problem with True or False Boolean.
I have Defined a procedure weekend which takes a string as its input, and
returns the Boolean True if it's 'Saturday' or 'Sunday' and False
otherwise.
Here is my weekend function:
def weekend(day):
if day == 'Saturday' or day == 'Sunday':
return "True"
else:
return "False"
Here is my output:
>>>print weekend('Monday')
False
>>>print weekend('Saturday')
True
>>>print weekend('July')
False
But as you see in my code, I'm returning a string BUT I want to return a
Boolean True or False.
How can I do that?
Thanks.

No comments:

Post a Comment