How to check if a variable's type is primitive?

前端 未结 7 1196
难免孤独
难免孤独 2020-12-05 12:57

I don\'t know how to check if a variable is primitive. In Java it\'s like this:

if var.isPrimitive():
7条回答
  •  我在风中等你
    2020-12-05 13:50

    If it helps,

    In [1]: type(1)
    Out[1]: 
    
    In [2]: type('a')
    Out[2]: 
    
    In [3]: (type(5.4)
    Out[3]: 
    
    In [5]: type(object)
    Out[5]: 
    
    In [8]: type(int)
    Out[8]: 
    

提交回复
热议问题