Python 格式化

发布时间:2019-05-02 07:04:02编辑:auto阅读(2424)

    数字前面补0

    字符型:

    print('23'.zfill(5))

    数字型:

    print('%011d' % 124)

    日期与str互转:

    datetime 转 str

      str_date = datetime.now().strftime("%Y-%m-%d")   -------(%04d%02d%02d)此种格式化注意

    str 转 datetime

      start_date = datetime.strptime("2016-06-07", "%Y-%m-%d")  

关键字