pytutorial/python_basics/if
David Rotermund ca8956cfdd
Create README.md
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
2023-12-06 23:32:05 +01:00
..
README.md Create README.md 2023-12-06 23:32:05 +01:00

Flow Control if, elif, else

{:.no_toc}

* TOC {:toc}

The goal

If I would have...

Questions to David Rotermund

Logic blocks need to be indented. Preferable with 4 spaces!

The if statement

if i == 1:
    print("if")
elif i == 2:
    print("elif brach A")
elif i == 3:
    print("elif brach B")
else:
    print("else -- default")

The full statement

if_stmt ::=  "if" assignment_expression ":" suite
             ("elif" assignment_expression ":" suite)*
             ["else" ":" suite]