Fix Python – How do “and” and “or” act with non-boolean values?

I’m trying to learn python and came across some code that is nice and short but doesn’t totally make sense
the context was:
def fn(*args):
return len(args) and max(args)-min(args)

I get what it’s doing, but why does python do this – ie return the value rather than True/False?
10 and 7-2

returns 5. Similarly, changing the and to or will resul….

Fix Python – How do you get the logical xor of two variables in Python?

How do you get the logical xor of two variables in Python?
For example, I have two variables that I expect to be strings. I want to test that only one of them contains a True value (is not None or the empty string):
str1 = raw_input(“Enter string one:”)
str2 = raw_input(“Enter string two:”)
if logical_xor(str1, str2):
print “ok”
else:
prin….