format函数常与print()函数结合使用,具备很强的格式化输出能力。
1. 通过变量,逗号隔开:
print('{我}今天{action}'.format(我='脚踏前路',action ='在写博客')) # 通过关键字
输出:
2. 使用字典传入,在字典前加入**
grade = {'I' : '脚踏前路', '状态': '写博客'}
print('{I}在图书馆,{状态}'.format(**grade))#字典前加上**
输出:
3. 通过位置:
print('{0}今天{1}'.for