Chr*_*ian 8 python annotations type-hinting python-3.x
鉴于新的Python 3.5允许使用类型签名进行类型提示,我想使用新功能,但我不知道如何使用以下结构完全注释函数:
def yieldMoreIfA(text:str):
if text == "A":
yield text
yield text
return
else:
yield text
return
Run Code Online (Sandbox Code Playgroud)
什么是正确的签名?
有一种Generator[yield_type, send_type, return_type]类型:
from typing import Generator
def yieldMoreIfA(text: str) -> Generator[str, None, None]:
if text == "A":
yield text
yield text
return
else:
yield text
return
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
490 次 |
| 最近记录: |