From ca8956cfdda7d0881031152e16e0cb956f37534e Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Wed, 6 Dec 2023 23:32:05 +0100 Subject: [PATCH] Create README.md Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> --- python_basics/if/README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 python_basics/if/README.md diff --git a/python_basics/if/README.md b/python_basics/if/README.md new file mode 100644 index 0000000..fdae6a0 --- /dev/null +++ b/python_basics/if/README.md @@ -0,0 +1,37 @@ +# Flow Control if, elif, else +{:.no_toc} + + + +## The goal + +If I would have... + +Questions to [David Rotermund](mailto:davrot@uni-bremen.de) + +**Logic blocks need to be indented.​ Preferable with 4 spaces!** + +## [The if statement](https://docs.python.org/3/reference/compound_stmts.html#the-if-statement) + +```python +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 + +```python +if_stmt ::= "if" assignment_expression ":" suite + ("elif" assignment_expression ":" suite)* + ["else" ":" suite] +``` +