Einführung in Python für die Softwareentwicklung
George Boorman
Curriculum Manager, DataCamp
# Boolean variable
the_truth = True
print(the_truth)
True
Vergleichsoperatoren
*
, +
, -
usw.Prüfen, ob zwei Sachen gleich sind
==
# Compare if 2 is equal to 3
2 == 3
False
# Check that 2 is not equal to 3
2 != 3
True
# Is 5 less than 7?
5 < 7
True
# Is 5 less than or equal to 7?
5 <= 7
True
# Is 5 greater than 7?
5 > 7
False
# Is 5 greater or equal to 7?
5 >= 7
False
# Is James greater than Brian
"James" > "Brian"
True
Wenn WAHR (True
), erledige eine Aufgabe
if
> Bedingung erfüllt > Aktion ausführen
# Target units sold and actual units sold sales_target = 350 units_sold = 355
# Compare sales if units_sold >= sales_target
# Target units sold and actual units sold sales_target = 350 units_sold = 355
# Compare sales if units_sold >= sales_target:
# Target units sold and actual units sold sales_target = 350 units_sold = 355
# Compare sales if units_sold >= sales_target:
print("Target achieved")
'Target achieved'
# Target units sold and actual units sold sales_target = 350 units_sold = 355
# Compare sales if units_sold >= sales_target:
print("Target achieved") # This line is not indented
print("Target achieved")
^
IndentationError: expected an indented block
# Target units sold and actual units sold sales_target = 350 units_sold = 325
# Compare sales if units_sold >= sales_target:
print("Target achieved")
# Check if we were close to the target elif units_sold >= 320: print("Target almost achieved")
elif
-Keywords verwenden, wie wir wollen!# Compare sales if units_sold >= sales_target: print("Target achieved")
# Check if we were close to the target elif units_sold >= 320: print("Target almost achieved")
# Otherwise... else: print("Target not achieved")
Operator | Funktion |
---|---|
== |
gleich |
!= |
ungleich |
> |
Größer als |
>= |
Größer als oder gleich |
< |
Kleiner als |
<= |
Kleiner als oder gleich |
Schlüsselwort | Funktion | Benutzung |
---|---|---|
if |
Wenn die Bedingung erfüllt ist | An erster Stelle im Arbeitsablauf |
elif |
Ansonsten prüfe, ob diese Bedingung erfüllt ist | Nach if |
else |
Ansonsten führe das aus | Nach elif |
Einführung in Python für die Softwareentwicklung