Python:如何在列表中打印类型 [英] Python: How to print types within a list

查看:188
本文介绍了Python:如何在列表中打印类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此给了我一个列表,我必须打印列表中每个项目的类型.我可以清楚地看到有字符串和整数,但是我需要它才能在Python中打印出来.我们刚刚学习了 for循环,所以我觉得这就是他们想要的,但我无法打印出来.

So I was given a list and I must print the type of each item in the list. I can clearly see that there are strings and integers but I need it to print out in Python. We just learned for loops so I feel like that is what they are looking for but I cannot get it to print out.

推荐答案

ls = [type(item) for item in list_of_items]
print(ls)

这篇关于Python:如何在列表中打印类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆