测量程序编制 - python 54格式化输出:format用法.pptxVIP

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

测量程序编制 - python 54格式化输出:format用法.pptx

format 用法format用法相对基本格式化输出采用’%’的方法,format()功能更强大该函数把字符串当成一个模板通过传入的参数进行格式化并且使用大括号{}作为特殊字符代替%format用法hello worldhello worldhello world helloworld world helloworld hello worldprint({} {}.format(hello,world)) # 不带字段print({0} {1}.format(hello,world)) # 带数字编号print({0} {1} {0}.format(hello,world)) # 打乱顺序print({1} {1} {0}.format(hello,world))print({a} {tom} {a}.format(tom=hello,a=world)) # 带关键字1、位置/名字匹配(1)不带编号,即“{}”(2)带数字编号,可调换顺序,即“{1}”、“{2}”(3)带关键字,即“{a}”、“{tom}”format用法2、对象属性匹配c = 3-5jprint((complex{0},real:{0.real},imag:{0.imag}).format(c))complex(3-5j),real:3.0,imag:-5.0class Point: def __init

文档评论(0)

1亿VIP精品文档

相关文档