1 # 使用字符串的format()方法,对输出数据项进行格式化 2 x1, y1 = 1.2, 3.57 3 x2, y2 = 2.26, 8.7 4 # 输出1 5 print('{:-^40}'.format('输出1')) # {:-^40}控制输出数据格式: 宽度占40列,居中对齐,空白处用-补齐 6 print('x1 = {}, y1 = {}'.format(x1, y1)) 7 print('x2 = {}, y2 = {}'.format(x2, y2)) 8 # 输出2 9 print('{:-^40}'.format('输出2')) # {:-^40}控制输出数据格式: 宽度占40列,居中对齐,空白处用-补齐 10 print('x1 = {:.1f}, y1 = {:.1f}'.format(x1, y1)) # {:.1f}控制小数输出精度,保留1位小数 11 print('x2 = {:.1f}, y2 = {:.1f}'.format(x2, y2)) 12 # 输出3 13 print('{:-^40}'.format('输出3')) # {:-^40} 控制输出数据格式: 宽度占40列,居中对齐,空白处用-补齐 14 print('x1 = {:<15.1f}, y1 = {:<15.1f}'.format(x1, y1)) # {:<15.1f}控制数据输出宽度占15列,小数部分占1列,左对齐,空白处默认补空格 15 print('x2 = {:<15.1f}, y2 = {:<15.1f}'.format(x2, y2)) 16 # 输出4 17 print('{:-^40}'.format('输出3')) # {:-^40} 控制输出数据格式: 宽度占40列,居中对齐,空白处用-补齐View Code
标签:输出,AA0002,format,print,40,Moduel,Test,y1,x1 From: https://www.cnblogs.com/Luke-FOX-31415926/p/17191260.html