介绍
这篇文章将为大家详细讲解有关python判断对象是不是列表的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
在实际写程序中,<强>经常要对变量类型进行判断,,可以用isinstance方法判断>强,也可以用类型(变量)这种方法(<强> python官方文档在说明类型函数的用法时,明文推荐用isinstance测试对象类型。强>):
# !/usr/bin/env python a =1 b =, (1、2、3、4) c =, (1, 2, 3, 4) d =,{& # 39;一个# 39;:1 & # 39;b # 39;: 2 & # 39; c # 39;: 3} 时间=e “abc" if isinstance (int): ,,,print “a is int" 其他: ,,,print “a is not int" if isinstance (b,列表): ,,,print “b is list" 其他: ,,,print “b is not list" if isinstance (c,元组): ,,,print “c is tuple" 其他: ,,,print “c is not tuple" dict if isinstance (d): ,,,print “d is dict" 其他: ,,,print “d is not dict" str if isinstance (e): ,,,print “d is str" 其他: ,,,print “d is not str"
关于python判断对象是不是列表的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看的到。