When you use a logical operator, it continues in accordance with the rules, so with and, it evaluates the veracity of the first operator and, if it is not truthful, it returns an implausible value (in the first case, ``).
print repr("" and "THIS IS POST AND") "" print "" or "THIS IS POST AND" THIS IS POST AND print None or "Something else" Something else
If this is convenient for you, this is when you do not want to call a non-existent method on something like None (for example, length):
r = None s = [1,2,3,4] print r and len(r) None print s and len(s) 4
In the case when you sent a message, the fact is that you want to check the username only for regular expression, if the username is true.
It is important to note here that and and or both short circuits. Therefore, if you get something implausible, the function will not even evaluate the regular expression.
Jeff tratner
source share