测量程序编制 - python 55格式化输出:format用法(进阶用法).pptxVIP

  • 3
  • 0
  • 约2.07千字
  • 约 8页
  • 2022-04-11 发布于江西
  • 举报

测量程序编制 - python 55格式化输出:format用法(进阶用法).pptx

format 用法 5、进阶用法 1)进制转换 format用法 print(int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}.format(42)) # 在前面加“#”,则带进制前缀 print(int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}.format(42)) int: 42; hex: 2a; oct: 52; bin: 101010 int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010 5、进阶用法 2)左中右对齐及位数补全 (1) (默认)左对齐、 右对齐、^ 中间对齐、= (只用于数字)在小数点 后进行补齐 (2)取位数“{:4s}”、{:.2f}等 format用法 print({} and {}.format(hello,world)) # 默认左对齐 print(‘{:10s} and {:10s}’.format(‘hello’,‘world’)) # 取10位左/右对齐 print({:^10s} and {:^10s}.format(hello,world)) # 取10位中间对齐 print({}

文档评论(0)

1亿VIP精品文档

相关文档