Union
联合类型
Union[int, str] 表示既可以是 int,也可以是 str
等价写法
vars: Union[int, str]
# 等价于vars: [intorstr]
vars: Union[int]
# 等价于vars: int
union 等价写法
Union
[
int
] ==
int
最终 Union[int] 返回的也是 int 类型
Union
[
int
,
str
,
int
] ==
Union
[
int
,
str
]
重复的类型参数会自动忽略掉
Union
[
int
,
str
] ==
Union
[
str
,
int
]
自动忽略类型参数顺序
Union
[
Union
[
int
,
str
],
float
] ==
Union
[
int
,
str
,
float
]