从包含整数,字符串和浮点数的列表中,制作三个列表以分别存储它们。
请帮助我如何根据类型分隔列表值。
答案 0 :(得分:-2)
您可以使用文字。
test = [3, "hello", 2.4]
int_array = []
string_array = []
float_array = []
for value in test:
check = type(value)
if check == int:
int_array.append(value)
elif check == str:
string_array.append(value)
elif check == float:
float_array.append(value)