实验任务1
task1-1
Python源码
1 print('hey,u') 2 print('hey', 'u') 3 x,y,z = 1,2,3 4 print(x,y,z)
1 x,y,z = 1,2,3 2 print('x = %d, y = %d, z = %d' %(x,y,z)) 3 print('x = {}, y = {}, z = {}'.format(x,y,z)) 4 print(f'x = {x}, y = {y}, z = {z}') 5 6 7 print(x) 8 print(y) 9 print(z) 10 11 12 print(x, end=' ') 13 print(y, end=' ') 14 print(z)
运行截图
task1-2
1 x1, y1 = 1.2, 3.57 2 x2, y2 = 2.26, 8.7 3 4 print('{:-^40}'.format('输出1')) 5 print('x1 = {}, y1 = {}'.format(x1, y1)) 6 print('x2 = {}, y2 = {}'.format(x2, y2)) 7 8 9 print('{:-^40}'.format('输出2')) 10 print('x1 = {:.1f}, y1 = {:.1f}'.format(x1, y1)) 11 print('x2 = {:.1f}, y2 = {:.1f}'.format(x2, y2)) 12 13 14 print('{:-^40}'.format('输出3')) 15 print('x1 = {:<15.1f}, y1 = {:<15.1f}'.format(x1, y1)) 16 print('x2 = {:<15.1f}, y2 = {:<15.1f}'.format(x2, y2)) 17 18 19 print('{:-^40}'.format('输出4')) 20 print('x1 = {:>15.1f}, y1 = {:>15.1f}'.format(x1, y1)) 21 print('x2 = {:>15.1f}, y2 = {:>15.1f}'.format(x2, y2))View Code
task1-3
1 name1, age1 = 'Bill', 19 2 name2, age2 = 'Helle', 18 3 title = 'Personnel Information' 4 5 print(f'{title:^40}') 6 print(f'name:{name1:10} age" {age1:3}') 7 print(f'name:{name2:10} age" {age2:3}') 8 print(40*'=')View Code
实验总结
print()的常用的几种输出方式:1.用于输出单个字符串或单个变量print(' ')。2.用于输出多个数据项,用逗号隔开print(' ', ' ')
实验任务2
标签:初体验,format,Python,x1,编程,x2,y1,print,y2 From: https://www.cnblogs.com/202280060019x/p/17191453.html