一、基础PRINT FORMATTED OUTPUT 1、知识%形式输出
1.1 匹配字符,基础整数,知识浮点数(含精度),企商汇基础%类似转义

print("my name is 知识%s,age %d height %.2fm learning python progress is 基础3%%s." %(burton,33,1.785))
output result:my name is burton,age 33 height 1.78m learning python progress is 知识3%s.
1.2 指定占位符宽度、左右对齐和填充
print ("Name:%-10s Age:%08d Height:%8.2f"%("Aviad",基础25,1.833))
output result:Name:Aviad Age:00000025 Height: 1.83
1.3 有以下格式符
%s 字符串 (采用str()的服务器租用显示)
%r 字符串 (采用repr()的显示)
%c 单个字符
%b 二进制整数
%d 十进制整数
%i 十进制整数
%o 八进制整数
%x 十六进制整数
%e 指数 (基底写为e)
%E 指数 (基底写为E)
%f 浮点数
%F 浮点数,与上相同
%g 指数(e)或浮点数 (根据显示长度)
%G 指数(E)或浮点数 (根据显示长度)
%% 字符"%"
2、知识format形式输出
2.1 位置传参
li = [burton,基础18,178]
print(my name is {} ,age {}.format(burton,18))
print(my name is {1} ,age .format(18,burton))
print(my name is ,age {1}.format(*li))
print(name is {0[0]} age is {0[1]}.format(li))
output result:
my name is burton ,age 18
2.2 关键字传参
hash = {name:burton,age:18,heigth:178}
print(my name is {name},age is {age}.format(name=burton,age=18))
print(my name is {name},age is {age}.format(**hash))
output result:my name is burton ,age 18
2.3 填充与格式化
print({0:*>8}.format(18)) ##右对齐 站群服务器相关文章: