请问下:typing.Union
和 |
符号有什么区别吗?
from typing import Union
def test(p: Union[str, int]):
print(p)
pass
test("您好")
===
效果和此没有区别:
from typing import Union
def test(p: str | int):
print(p)
pass
test("您好")
请问下:typing.Union
和 |
符号有什么区别吗?
from typing import Union
def test(p: Union[str, int]):
print(p)
pass
test("您好")
===
效果和此没有区别:
from typing import Union
def test(p: str | int):
print(p)
pass
test("您好")
2 回答3.7k 阅读✓ 已解决
4 回答4.1k 阅读
4 回答3.9k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
2 回答1.6k 阅读✓ 已解决
2 回答621 阅读✓ 已解决
4 回答2.4k 阅读✓ 已解决
3.10 以后他们是等价的。
3.9 之前只能用 Union。
Union Type