In the actual writing program, the variable type is often judged, in addition to the type (variable) This method, you can also use the isinstance method to determine:
#!/usr/bin/env pythona = 1b = [1,2,3,4]c = (1,2,3,4) d = {' a ': 1, ' B ': 2, ' C ':3}e = "abc" if isinstance (a,int): print "A is int" else: print "A is not int "If isinstance (b,list): print " B is list "else: print "B is not list" If isinstance (c,tuple): print "C is tuple" else: print "C is not tuple" if Isinstance (d,dict): print "D is dict" Else: print "D is not dict" If isinstance (e,str): print "D is str "else: print " D is not str "
This article is from the "bitter coffee ' s Yun ' an Road" blog, please be sure to keep this source http://alsww.blog.51cto.com/2001924/1787848
Python determines whether a variable is an int, a string, a list, a tuple, a dictionary, and so on