Compound Statements
Compound statements and comparisons allow comparisons of 2 or more things in a single statement.
>>> x = 5
>>> 3 < x < 7
True
or:
>>> False == False in [False]
True
Abstract Syntax Tree#
One can use ast
to invetigate:
import ast
print(ast.dump(ast.parse('False == False in [False]'), indent=4))
Module(
body=[
Expr(
value=Compare(
left=Constant(value=False),
ops=[
Eq(),
In()],
comparators=[
Constant(value=False),
List(
elts=[
Constant(value=False)],
ctx=Load())]))],
type_ignores=[])
It shows comparison of the left value being compared against both the middle and right values.
Assigning 2 variables at once:
>>> print(ast.dump(ast.parse('x = y =7'), indent=4))
Module(
body=[
Assign(
targets=[
Name(id='x', ctx=Store()),
Name(id='y', ctx=Store())],
value=Constant(value=7))],
type_ignores=[])