其他分享
首页 > 其他分享> > typing模块

typing模块

作者:互联网

typing模块

作用

typing模块仅在Python3.5以上版本中可用,pycharm目前支持typing检查。

使用

from typing import List, Tuple, Dict

# 可提示列表、元组和字典内元素的类型.
def func(x:List[int], y:Tuple[str,float],z:Dict[str,int])->List:
    return x

func(10,20,30)  # 并不会抛异常,仅有提示作用.

Python本身也支持这种语法,但没有typing模块细腻。

def f(a:list,b)->tuple:
    return a,

f(1,2)

typing常用的类型

标签:int,List,Dict,模块,typing,类型
来源: https://www.cnblogs.com/ChiRou/p/14272349.html