You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
zahl =float(input("Zahl > ") # Achtung, kann `ValueError()` "werfen"
90
+
addition =5+3# 8
91
+
subtraktion =10-4# 6
92
+
multiplikation =6*7# 42
93
+
multiplikation_float =6.0*7# 42.0
94
+
division =15/3# 5.0
95
+
ganzzahldivision =17//5# 3
96
+
modulo =17%5# 2
97
+
potenz =2**3# 8
129
98
```
130
99
131
100
## Bedingungen (`if`)
@@ -146,22 +115,6 @@ if alter >= 18 and alter < 65:
146
115
print("Arbeitsfähig")
147
116
```
148
117
149
-
## Boolesche Werte
150
-
151
-
```python
152
-
wahr=True
153
-
falsch=False
154
-
155
-
wahr=TrueandTrue
156
-
wahr=TrueorFalse
157
-
158
-
wahr=notFalse
159
-
falsch=notTrue
160
-
161
-
falsch=FalseorFalse
162
-
falsch=TrueandFalse
163
-
```
164
-
165
118
## Schleifen
166
119
167
120
### `while`
@@ -204,6 +157,25 @@ for index, wert in enumerate(fruechte):
204
157
print(f"{index}: {wert}")
205
158
```
206
159
160
+
## Funktionen (`def`)
161
+
162
+
```python
163
+
defbegruessung():
164
+
print("Hallo!")
165
+
166
+
defaddiere(a, b):
167
+
return a + b
168
+
169
+
defquadrat(zahl=1): # Standardwert
170
+
return zahl **2
171
+
172
+
# Aufrufe
173
+
begruessung()
174
+
ergebnis = addiere(5, 3) # 8
175
+
wert = quadrat(4) # 16
176
+
standard = quadrat() # 1
177
+
```
178
+
207
179
## Importieren von Code (`import`)
208
180
209
181
```python
@@ -224,66 +196,6 @@ heute = dt.date.today()
224
196
from math import*
225
197
```
226
198
227
-
## Dokumentation
228
-
229
-
### Kommentare
230
-
231
-
```python
232
-
kein_kommentar # Kommentar
233
-
```
234
-
235
-
### docstrings
236
-
237
-
Am Anfang einer Datei, Funktion, Klasse, … kann ein String plaziert werden, welche von der Funktion `help()` für die Dokumentation genutzt wird. Es haben sich verschiedene Formatierungen entwickelt. Hier wird eine vorgestellt.
238
-
239
-
```python
240
-
"""Lend or return media, if within allowed number of media on account.
241
-
242
-
Parameters:
243
-
-----------
244
-
account_balance (int): The current balance before the transaction is attempted.
245
-
Valid values: 0 <= x <= 15
246
-
247
-
number_of_media (int): The number of the media to be lent or returned.
248
-
A positive number signifies lending and a negative Number signifies returning.
249
-
250
-
Returns:
251
-
--------
252
-
int: The current account balance.
253
-
"""
254
-
```
255
-
256
-
## Ausführbare Skripte
257
-
258
-
### Shebang
259
-
260
-
Nur die erste Zeile des Skripts kann als Shebang benutzt werden!
261
-
262
-
```python
263
-
#! /usr/bin/env python3
264
-
```
265
-
266
-
### `if __name__ == "__main__":`
267
-
268
-
```python
269
-
wird_immer_ausgeführt=1# bspw. beim Importieren
270
-
def das_auch():
271
-
print("wird ausgeführt, wenn die Funktion aufgerufen wird")
272
-
...
273
-
274
-
if__name__=="__main__":
275
-
wird_nur_als_skript="ausgeführt"
276
-
das_auch()
277
-
```
278
-
279
-
### Datei ausführbar machen
280
-
281
-
In Unix-artigen Betriebssystemen.
282
-
283
-
```bash
284
-
$ chmod +x datei.py
285
-
```
286
-
287
199
## Listen (`list`)
288
200
289
201
```python
@@ -335,6 +247,34 @@ for schluessel in person.keys():
335
247
print(schluessel)
336
248
```
337
249
250
+
## Nützliche eingebaute Funktionen
251
+
252
+
### `print()`
253
+
254
+
```python
255
+
print("Hallo Welt") # Hallo Welt
256
+
print("Name:", "Alice", "Alter:", 25) # Name: Alice Alter: 25
zahl =float(input("Zahl > ") # Achtung, kann `ValueError()` "werfen"
276
+
```
277
+
338
278
## Dateien lesen und schreiben
339
279
340
280
```python
@@ -399,6 +339,66 @@ finally:
399
339
print("Wird immer ausgeführt")
400
340
```
401
341
342
+
## Dokumentation
343
+
344
+
### Kommentare
345
+
346
+
```python
347
+
kein_kommentar # Kommentar
348
+
```
349
+
350
+
### docstrings
351
+
352
+
Am Anfang einer Datei, Funktion, Klasse, … kann ein String plaziert werden, welche von der Funktion `help()` für die Dokumentation genutzt wird. Es haben sich verschiedene Formatierungen entwickelt. Hier wird eine vorgestellt.
353
+
354
+
```python
355
+
"""Lend or return media, if within allowed number of media on account.
356
+
357
+
Parameters:
358
+
-----------
359
+
account_balance (int): The current balance before the transaction is attempted.
360
+
Valid values: 0 <= x <= 15
361
+
362
+
number_of_media (int): The number of the media to be lent or returned.
363
+
A positive number signifies lending and a negative Number signifies returning.
364
+
365
+
Returns:
366
+
--------
367
+
int: The current account balance.
368
+
"""
369
+
```
370
+
371
+
## Ausführbare Skripte
372
+
373
+
### Shebang
374
+
375
+
Nur die erste Zeile des Skripts kann als Shebang benutzt werden!
376
+
377
+
```python
378
+
#! /usr/bin/env python3
379
+
```
380
+
381
+
### `if __name__ == "__main__":`
382
+
383
+
```python
384
+
wird_immer_ausgeführt=1# bspw. beim Importieren
385
+
def das_auch():
386
+
print("wird ausgeführt, wenn die Funktion aufgerufen wird")
0 commit comments