Python Advanced (2023-10-09 - 2023-10-09)¶
JSON¶
[1]:
d = {
'eins': 1,
'zwei': 2,
# ...
}
[2]:
import json
[3]:
d_str = json.dumps(d)
[5]:
d_str
[5]:
'{"eins": 1, "zwei": 2}'
[6]:
type(d_str)
[6]:
str
Jetzt uebertragen wir die Daten …
[7]:
d_str_received = d_str
[8]:
d_received = json.loads(d_str_received)
[10]:
d_received
[10]:
{'eins': 1, 'zwei': 2}
Type Annotations¶
[11]:
def f(i: int) -> str:
return str(i)
[12]:
f.__annotations__
[12]:
{'i': int, 'return': str}
[ ]: