Shaping the date using Python modules

Asked 2 years ago, Updated 2 years ago, 34 views

Do you want to format data from the SQL database with python?
In this case, wouldn't it be possible to simplify the date using the module?
Also, I would like to round off 2.26 and mark it as 2.3%.

Before plastic surgery
[(datetime.date(2016, 7, 17), 2.26268624680273)]

After plastic surgery
Jully 17,2016—2.3% errors

python python3

2022-09-30 17:35

1 Answers

Since you are using Python 3, I think using the format method is the most natural.

The f option also makes it easy to specify the number of decimal places.

ls=[(datetime.date(2016, 7, 17), 2.26268624680273)]
fort, vinls:
    print("{}-{:1f}% errors".format(t.strftime("%B%d,%Y"),v))

Note: http://uxmilk.jp/40547


2022-09-30 17:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.