When defining a function, * means to collect parameters, and ** means to collect keyword parameters.
env = {**os.environ}
os.environ is not a dict,why the above code works?
When defining a function, * means to collect parameters, and ** means to collect keyword parameters.
env = {**os.environ}
os.environ is not a dict,why the above code works?
Although **
is typically used on dictionaries, it allows you to unpack any Mapping
.
Note that:
import os
from typing import Mapping
print(isinstance(os.environ, Mapping))
Prints:
True
Similarly, *
allows you to unpack any iterable.