You can use the ast
module to see how Python parses the two differently.
In the first case, the parser recognizes is not
as a single (two-word) operator, with operands one
and False
.
>>> print(ast.dump(ast.parse("one is not False"), indent=4))
Module(
body=[
Expr(
value=Compare(
left=Name(id='one', ctx=Load()),
ops=[
IsNot()],
comparators=[
Constant(value=False)]))],
type_ignores=[])
In the second case, the parser recognizes is
as a single (one-word) operator, with operands one
and not False
.
>>> print(ast.dump(ast.parse("one is (not False)"), indent=4))
Module(
body=[
Expr(
value=Compare(
left=Name(id='one', ctx=Load()),
ops=[
Is()],
comparators=[
UnaryOp(
op=Not(),
operand=Constant(value=False))]))],
type_ignores=[])