#实验任务1 #1.1.py #用法1 print('hey,u') #用法2 print('hey','u') x,y,z=1,2,3 print(x,y,z) #用法3 print('x=%d,y=%d,z=%d'%(x,y,z)) print('x={},y={},z={}'.format(x,y,z)) print(f'x={x},y={y},z={z}') #其他 print(x) print(y) print(z) print(x,end='') print(y,end='') print(z)
#task1_2py # 使用字符串的format()方法,对输出数据项进行格式化 x1, y1 = 1.2, 3.57 x2, y2 = 2.26, 8.7 #输出1 print('{:-^40}'.format('输出1')) print('x1={},y1={}'.format(x1,y1)) print('x2={},y2={}'.format(x2,y2)) #输出2 print('{:-^40}'.format('输出2')) print('x1={:.1f},y1={:.1f}'.format(x1,y1)) print('x2={:.1f},y2={:.1f}'.format(x2,y2)) #输出3 print('{:-^40}'.format('输出3')) print('x1={:<15.1f},y1={:<15.1f}'.format(x1,y1)) print('x2={:<15.1f},y2={:<15.1f}'.format(x2,y2)) #输出4 print('{:-^40}'.format('输出4')) print('x1={:>15.1f},y1={:>15.1f}'.format(x1,y1)) print('x2={:>15.1f},y2={:>15.1f}'.format(x2,y2))
#task1_3.py #使用f-string方式输出数据并控制格式 name1,age1='Bill',19 name2,age2='Hellen',18 title='Personnel Information' print(f'{title:=^40') print(f'name:{name1:10} age:{age1:3}') print(f'name:{name2:10} age:{age2:2}') print(40*'=')
标签:初体验,y1,format,Python,x1,编程,x2,print,y2 From: https://www.cnblogs.com/cxb17/p/17197048.html