Various Python guides say to use x is None instead of x == None. Why is that? Equality is used for comparing values, so it seems natural to ask if x has the value None, denoted with == and not is. Can someone explain why is is the preferred form and show an example where the two do not give the same answer?
Thanks.
The reason people use
isis because there is no advantage to using==. It is possible to write objects that compare equal toNone, but it is uncommon.Output:
The
isoperator is also faster, but I don’t consider this fact important.