Checking if type == list in python

后端 未结 5 1707
孤城傲影
孤城傲影 2020-12-01 04:08

I may be having a brain fart here, but I really can\'t figure out what\'s wrong with my code:

for key in tmpDict:
    print type(tmpDict[key])
    time.sleep         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 04:45

    Although not as straightforward as isinstance(x, list) one could use as well:

    this_is_a_list=[1,2,3]
    if type(this_is_a_list) == type([]):
        print("This is a list!")
    

    and I kind of like the simple cleverness of that

提交回复
热议问题