Fastest way to insert these dashes in python string?

前端 未结 8 1482
失恋的感觉
失恋的感觉 2021-02-13 16:34

So I know Python strings are immutable, but I have a string:

c[\'date\'] = \"20110104\"

Which I would like to convert to

c[\'da         


        
8条回答
  •  独厮守ぢ
    2021-02-13 17:18

    Dates are first class objects in Python, with a rich interface for manipulating them. The library is datetime.

    > import datetime
    > datetime.datetime.strptime('20110503','%Y%m%d').date().isoformat()
    '2011-05-03'
    

    Don't reinvent the wheel!

提交回复
热议问题