Einführung in Python für die Softwareentwicklung
George Boorman
Curriculum Manager, DataCamp
Syntax | Aktion | Beispiel | Ergebnis |
---|---|---|---|
* |
Multiplikation | 4 * 10 |
40 |
+ |
Addition | 7 + 9 |
16 |
- |
Subtraktion | 23 - 4 |
19 |
/ |
Division | 27 / 3 |
9 |
** |
Potenz | 3 ** 2 |
9 |
% |
Modulo | 7 % 4 |
3 |
# Define total_spend total_spend = 3150.96
# Single quotes customer_name = 'George Boorman'
# Double quotes also work customer_name = "George Boorman"
current_top_album = "For All The Dogs"
# Convert to lowercase current_top_album = current_top_album.lower()
# List of prices prices = [10, 20, 30, 15, 25, 35]
# Get the value at the first index prices[0]
# Creating a dictionary
products_dict = {"AG32": 10, "HT91": 20,
"PL65": 30, "OS31": 15,
"KB07": 25, "TR48": 35}
# Create a prices set prices_set = {10, 20, 30, 15, 25, 35}
# Create a prices tuple prices_tuple = (10, 20, 30, 15, 25, 35)
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 |
# Prices list prices = [9.99, 8.99, 35.25, 1.50, 5.75]
# Print each value in prices for price in prices:
print(price)
9.99
8.99
35.25
1.5
5.75
# Stock limit stock = 10 # Number of purchases num_purchases = 0
# While num_purchases < stock limit while num_purchases < stock:
# Increment num_purchases num_purchases += 1
# Print remaining stock print(stock - num_purchases)
Schlüsselwort | Funktion |
---|---|
and |
Prüft, ob mehrere Bedingungen wahr sind |
or |
Prüft, ob eine oder mehrere Bedingungen wahr sind |
in |
Prüft, ob ein Wert in einer Datenstruktur enthalten ist |
not |
Prüft, ob ein Wert nicht in einer Datenstruktur enthalten ist |
list.append()
Weitere eingebaute Funktionen
zip()
enumerate()
Pakete und Module
os
time
venv
pandas
requests
numpy
Einführung in Python für die Softwareentwicklung