我可以将Atyping.NamedTuple
解开作为参数或破坏性的作业,就像我可以使用A
tuple
?
from typing import NamedTuple
class Test(NamedTuple):
a: int
b: int
t = Test(1, 2)
# destructuring assignment
a, b = t
# a = 1
# b = 2
def f(a, b):
return f"{a}{b}"
# unpack
f(*t)
# '12'
包装顺序是定义中字段的顺序。