1. 函数代码
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
2. 测试
(1)测试代码
if __name__ == '__main__':
A = 'S1'
B = 1
print(typeof(A))
print(typeof(B))
(2)测试结果