
占位符号
%d:digit 整形
%f:float 浮点型
%s: string 字符串
date=1
date1=1.1
date2="11"
print("date is %d,date2 is %.1f,date2 is %s"%(date,date1,date2))
#date is 1,date2 is 1.1,date2 is 11
固定输出占位
%4d 右对齐 占4位
%-4d 左对齐 占4位
%8.4f 右对齐 占8位 有效数字小数后4位
%+10d 右对齐 占10位输出带加号
新版date=1
date1=1.1
date2="11"
print(f"date is {date},date2 is {date1},date2 is {date2}")
#date is 1,date2 is 1.1,date2 is 11
{date:4} 占4位右对齐 默认等同{date:>4}
{date:<4} 占4位左对齐
{date:^4} 占4位中间对齐
{date:*^4}占4位中间对齐 空白用 * 号填充 此处星号可变为单字符
{date:x^4}占4位中间对齐 空白用 x 填充
注 此处date 为变量名 可灵活改变