内置函数-format()

# 字符串串
print(format('test', '<20')) # 左对⻬齐
print(format('test', '>20')) # 右对⻬齐
print(format('test', '^20')) # 居中
# 数值
print(format(3, 'b')) # ⼆二进制
print(format(97, 'c')) # 转换成unicode字符
print(format(11, 'd')) # ⼗十进制
print(format(11, 'o')) # ⼋八进制
print(format(11, 'x')) # ⼗十六进制(⼩小写字⺟母)
print(format(11, 'X')) # ⼗十六进制(⼤大写字⺟母)
print(format(11, 'n')) # 和d⼀一样
print(format(11)) # 和d⼀一样
# 浮点数
print(format(123456789, 'e')) # 科学计数法. 默认保留留6位⼩小数
print(format(123456789, '0.2e')) # 科学计数法. 保留留2位⼩小数(⼩小写)
print(format(123456789, '0.2E')) # 科学计数法. 保留留2位⼩小数(⼤大写)
print(format(1.23456789, 'f')) # ⼩小数点计数法. 保留留6位⼩小数
print(format(1.23456789, '0.2f')) # ⼩小数点计数法. 保留留2位⼩小数
print(format(1.23456789, '0.10f')) # ⼩小数点计数法. 保留留10位⼩小数
print(format(1.23456789e+10000, 'F')) # ⼩小数点计数法.
原文地址:https://www.cnblogs.com/fan-gx/p/12812228.html