typing模块

typing模块

一、导入方式

from typing import xxx

二、作用

提供生成器类型(cenerator),可迭代类型(iterable),迭代器类型(iterator)三种数据类型,限制函数

三、方法

from typing import Generator,Iterable,Iterator
#          参数的数据类型                                              返回值
def func(i: int, f: float, b: bool, lt: list, tup: tuple, dic: dict,g:Generator) -> tuple:
    lis = [i, f, b, lt, tup, dic]
    return tuple(lis)
# i, f, b, lt, tup, dic = func(1,2,3,4,5,6) # 不错误,只是不规范
def ger():
    yield
res = func(1, 2, True, [1, 2], (1, 2), {'a': 1},ger())
print(res)
-----------------------------------------------------
(1, 2, True, [1, 2], (1, 2), {'a': 1})
posted @ 2019-08-20 14:21  JIAYIYAN  阅读(313)  评论(0编辑  收藏  举报