#1.设定位置和不设定位置
>>>"{} {}".format("hello", "world") # 不设置指定位置,按默认顺序
'hello world'
>>> "{0} {1}".format("hello", "world") # 设置指定位置
'hello world'
>>> "{1} {0} {1}".format("hello", "world") # 设置指定位置
'world hello world'
2.数字的格式化输出
#1.数字->字符串 两种方式
m_f=123.454
text1='{:.2f}'.format(m_f) #输出2位小数 123.45
text11='{:+.2f}'.format(m_f) #带符号 保留两位小数 +123.45
text2='%.3f' % m_f #输出3位小数
#2.设置数字宽度 数值不变
m_d=123
text3 = '{:0>10f}'.format(m_f) # float 10 为宽度 f为类型 123.454000 补的是小数点后
# text3 = '{:0>5d}'.format(m_d) # int 5 为宽度 d为类型 填左边
print(text3)
#3.百分比格式
f=0.25
text4='{:.3%}'.format(f) #3是小数点后的位数 25.000%
print(text4)
#4.
coe=1092
h=hex(coe) #0x444
print(h)
text5 = '{:#06X}'.format(coe) #0X0444 按照6位宽度输出
print(text5)
#5.10进制转换成其它进制
'{:b}'.format(11) #2进制
'{:d}'.format(11) #10进制
'{:o}'.format(11) #8进制
'{:x}'.format(11) #16进制
'{:#x}'.format(11) #16进制小写
'{:#X}'.format(11) #16进制大写