Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
darkwind1374282dAnd she is correct
>>> def foo(x, y):
>>> print((x and (not y)) or ((not x) and y))
>>> def bar(x, y):
>>> print(x != y)
>>> def printer(func):
hitko2597282d@shehanthamel (!x ^ !y), or (!x != !y) (if x and y are already both booleans, you can just write x^y or x!=y)
ScriptCoded17888282d@shehanthamel That works, but I'd probably use the first just for the sake of writing clear code.
If they're bools, perhaps x !== y?
x ^ y - runs xor for x and y, works well in this case if x and y are bool only. Returns 1 or 0.
!!x ^ !!y - converts to bool and runs xor. Returns 1 or 0.
!!(!!x ^ !!y) - converts to bool, runs xor, converts result to bool true / false.
So pick one for your use case :)