Python: how can I check whether an object is of type datetime.date?

后端 未结 7 1179
既然无缘
既然无缘 2020-12-24 10:16

I have tried a few obvious options but none of them works:

In [150]: x
Out[150]: datetime.date(2012, 9, 1)

In [151]: type(x)
Out[151]: datetime.date

In [15         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 10:46

    import datetime
    d = datetime.date(2012, 9, 1)
    print type(d) is datetime.date
    
    > True
    

提交回复
热议问题