Bedingungen
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
# Der If Befehl ermöglicht es, dass bestimmte Anweisungen nur unter bestimmten Bedingungen ausgeführt werden.
|
||||||
|
|
||||||
|
if True:
|
||||||
|
print("Dieser Code wird immer ausgeführt, da die Bedingung True ist.")
|
||||||
|
|
||||||
|
if False:
|
||||||
|
print("Dieser Code wird nie ausgeführt, da die Bedingung False ist.")
|
||||||
|
|
||||||
|
boolean_variable: bool = True
|
||||||
|
if boolean_variable:
|
||||||
|
print("Dieser Code wird ausgeführt, da boolean_variable den Wert True hat.")
|
||||||
|
|
||||||
|
if not boolean_variable:
|
||||||
|
print("Dieser Code wird nicht ausgeführt, da boolean_variable den Wert True hat und die Bedingung not boolean_variable somit False ist.")
|
||||||
|
|
||||||
|
text: str = "Hallo, Welt!"
|
||||||
|
if text == "Hallo, Welt!":
|
||||||
|
print("Dieser Code wird ausgeführt, da die Bedingung text == 'Hallo, Welt!' True ist.")
|
||||||
|
|
||||||
|
|
||||||
|
if boolean_variable and text == "Hallo, Welt!":
|
||||||
|
print("Dieser Code wird ausgeführt, da beide Bedingungen True sind.")
|
||||||
|
|
||||||
|
|
||||||
|
if boolean_variable or text == "Hallo, Welt!":
|
||||||
|
print("Dieser Code wird ausgeführt, da mindestens eine der Bedingungen True ist.")
|
||||||
|
|
||||||
|
zahl: int = 5
|
||||||
|
if zahl > 0 and zahl < 10:
|
||||||
|
print("Dieser Code wird ausgeführt, da beide Bedingungen True sind.")
|
||||||
|
|
||||||
|
nichts: None = None
|
||||||
|
if nichts is None:
|
||||||
|
print("Dieser Code wird ausgeführt, da die Bedingung nichts is None True ist.")
|
||||||
@@ -19,6 +19,6 @@ text: str = "Hallo, Welt!"
|
|||||||
number: int = 42
|
number: int = 42
|
||||||
dezimal: float = 3.14159
|
dezimal: float = 3.14159
|
||||||
boolean: bool = True
|
boolean: bool = True
|
||||||
list_of_numbers: list = [1, 2, 3, 4, 5]
|
list_of_numbers: list[int] = [1, 2, 3, 4, 5]
|
||||||
dictionary: dict = {"name": "Max Mustermann", "age": 30}
|
dictionary: dict = {"name": "Max Mustermann", "age": 30}
|
||||||
two_variables: tuple = (1, "Hallo")
|
two_variables: tuple = (1, "Hallo")
|
||||||
|
|||||||
Reference in New Issue
Block a user