108-Python中常用f-string用法
Python中常用f-string用法
import datetime
now = datetime.datetime.now()
print(f'{now:%Y-%m-%d %H:%M}')
print(f'{now:%d/%m/%y %H:%M:%S}')
# 2023-10-02 06:11
# 02/10/23 06:11:52
pi = 3.141592653589793238462643
f'{pi:.2f}'
# '3.14'
pi = 3.141592653589793238462643
f'{pi * 1000:.2e}'
# '3.14e+03'
a = 18
print(f"{a:b}")
# 10010
a = 68
print(f"{a:x}")
# 44
a = 88
print(f"{a:o}")
# 130