JA-*_*sta 3 python type-hinting python-3.x
使用类型提示库typing是否可以组合两种类型?我想要一个 singlestr或 alist of str作为参数。见下文:
from typing import Dict, Optional, List
def run_ml(
estimator: Estimator,
parameters: Optional[Dict[str, List[str]]] = None,
):
Run Code Online (Sandbox Code Playgroud)
是的。您可以使用联盟。
例子
def send_email(address: Union[str, List[str]],
sender: str,
cc: Optional[List[str]],
bcc: Optional[List[str]],
subject='',
body: Optional[List[str]] = None
) -> bool:
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2800 次 |
| 最近记录: |