-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfunktionen.py
More file actions
executable file
·84 lines (59 loc) · 1.16 KB
/
funktionen.py
File metadata and controls
executable file
·84 lines (59 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
# Funktionen:
def funktion() -> None:
print("Hallo!")
funktion()
# OUT: Hallo!
def funktion(text: str) -> None:
print(text)
funktion("a")
# OUT: a
def funktion(text, wirklich):
if wirklich:
print(text)
funktion("Hallo", True)
# OUT: Hallo
funktion(True, "Hallo")
# OUT: True
def funktion(text: str = "Beispiel", wirklich: bool = False):
if wirklich:
print(text)
funktion()
# OUT: None
funktion(wirklich=True)
# OUT: Beispiel
funktion(wirklich=True, text="Abc")
# OUT: Abc
def ja() -> str:
return "Ja"
ja()
# OUT: 'Ja'
# beliebig viele Parameter
def sum(*params):
s = 0
for x in params:
s += x
return s
sum() # 0
sum(1,5) # 6
# beliebig viele Keyword-Argumente
def print_kwargs(**kwargs):
print(kwargs)
print_kwargs(a=5, b="foo")
# die allgemeinste Funktion
def allg(*args, **kwargs):
print(args, kwargs)
# Rekursion:
def fun() -> None:
print("Fun!")
fun()
# Quersumme:
def quersumme(zahl: int) -> int:
qs = 0
for ziffer in str(zahl):
qs += int(ziffer)
return qs
# Docstrings
def fun():
"""Diese Funktion macht Spaß."""
print("Spaß")