Python 의 isinstance

http://blog.csdn.net/business122/article/details/7608176
    isinstance  
      
    isinstance(object, classinfo)   
                object     
      
    classinfo    (tuple,dict,int,float)  
                  
      
    class objA:   
    pass   
      
    A = objA()   
    B = 'a','v'   
    C = 'a string'   
      
    print isinstance(A, objA)   
    print isinstance(B, tuple)   
    print isinstance(C, basestring)   
        :   
    True   
    True   
    True   
      
       
        ,     isinstance  ,                 。  
    isinstance    :  
        isinstance(object, class-or-type-or-tuple) -> bool  
          
        Return whether an object is an instance of a class or of a subclass thereof.  
        With a type as second argument, return whether that is the object's type.  
        The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for  
        isinstance(x, A) or isinstance(x, B) or ... (etc.).  
      
             ,                。        。                  True。         ,                    True。  
      
    >>>isinstance(lst, list)  
    True  
      
    >>>isinstance(lst, (int, str, list) )  
    True  
      :Python            ,  type  :>>>lst = [1, 2, 3]>>>type(lst)<type 'list'>  

좋은 웹페이지 즐겨찾기