使用 isinstance()函数,该函数有两个参数,第一个为填入的变量,第二个为类型(str,int,float,list,tuple,dict,set),返回值为布尔值
函数如下
def typeof(variate): type=None if isinstance(variate,int): type = "int" elif isinstance(variate,str): type = "str" elif isinstance(variate,float): type = "float" elif isinstance(variate,list): type = "list" elif isinstance(variate,tuple): type = "tuple" elif isinstance(variate,dict): type = "dict" elif isinstance(variate,set): type = "set" return type
原文地址:https://www.cnblogs.com/mafy/p/12005179.html
时间: 2024-11-18 20:57:14