我想在我的Python程序中使用类型提示。如何为复杂的数据结构创建类型提示,例如:
- 包含字符串的列表
- 返回整数的生成器?
示例
def names() -> list:
# I would like to specify that the list contains strings?
return ['Amelie', 'John', 'Carmen']
def numbers():
# Which type should I specify for `numbers()`?
for num in range(100):
yield num