may help you . This is called conditional expression and the Grammer for that is defined like

this```
conditional_expression ::= or_test ["if" or_test "else" expression]
```

```
or_test ::= and_test | or_test "or" and_test
```

```
and_test ::= not_test | and_test "and" not_test
```

```
not_test ::= comparison | "not" not_test
```

```
comparison ::= or_expr ( comp_operator or_expr )*
```

```
comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "!="
| "is" ["not"] | ["not"] "in"
```

```
or_expr ::= xor_expr | or_expr "|" xor_expr
```

```
xor_expr ::= and_expr | xor_expr "^" and_expr
```

```
and_expr ::= shift_expr | and_expr "&" shift_expr
```

```
shift_expr ::= a_expr | shift_expr ( "<<" | ">>" ) a_expr
```

```
a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr
```

```
m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr
| m_expr "%" u_expr
```

```
u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr
```

```
power ::= primary ["**" u_expr]
```

```
primary ::= atom | attributeref | subscription | slicing | call
```