How do you set a conditional in python based on datatypes?

后端 未结 5 656
长发绾君心
长发绾君心 2020-11-30 07:40

This question seems mind-boggling simple, yet I can\'t figure it out. I know you can check datatypes in python, but how can you set a conditional based on the datatype? For

5条回答
  •  一生所求
    2020-11-30 07:50

    let me declare variable x of type int

    x = 2
    if type(x) == type(1) or isinstance(x, int):  
        # do something
    

    Both works fine.

提交回复
热议问题