1 #判断变量类型的函数
2 def typeof(variate):
3 type=None
if isinstance(variate,numpy.ndarray):
5 type = "numpy.ndarray"
4 if isinstance(variate,int):
5 type = "int"
6 elif isinstance(variate,str):
7 type = "str"
8 elif isinstance(variate,float):
9 type = "float"
10 elif isinstance(variate,list):
11 type = "list"
12 elif isinstance(variate,tuple):
13 type = "tuple"
14 elif isinstance(variate,dict):
15 type = "dict"
16 elif isinstance(variate,set):
17 type = "set"
18 return type
19 # 返回变量类型
20 def getType(variate):
21 arr = {"int":"整数","float":"浮点","str":"字符串","list":"列表","tuple":"元组","dict":"字典","set":"集合"}
22 vartype = typeof(variate)
23 if not (vartype in arr):
24 return "未知类型"
25 return arr[vartype]