Python:如何在lis中打印类型

2024-03-29 08:00:32 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
3条回答

实际上,^{}函数接受一个对象并返回它的类型。请尝试以下代码:

for item in [1,2,3, 'string', None]:
    print type(item)

输出:

<type 'int'>
<type 'int'>
<type 'int'>
<type 'str'>
<type 'NoneType'>
ls = [type(item) for item in list_of_items]
print(ls)

下面是我将如何使用^{}来完成它。

myList = [1,1.0,"moo"]  #init the array
for i in myList: 
    print(type(i)) #loop and print the type

相关问题 更多 >