1. 程式人生 > 其它 >實驗1(!)

實驗1(!)

第一部分

print('hey,u')

print('hey','u')

x,y,z=1,2,3
print(x,y,z)


print('x=%s,y=%s,z=%s'%(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)

對應輸出

第二部分

x1,y1=1.2,3.57
x2,y2=2.26,8.7
print('{:-^40}'.format('
輸出1')) print('x1={},y1={}'.format(x1,y1)) print('x2={},y2={}'.format(x2,y2)) print('{:-^40}'.format('輸出2')) print('x1={:.1f},y1={:.1f}'.format(x1,y1)) print('x2={:.1f},y2={:.1f}'.format(x2,y2)) print('{:-^40}'.format('輸出3')) print('x1={:<15.1f},y1={:<15.1f}'.format(x1,y1)) print('x2={:<15.1f},y2={:<15.1f}
'.format(x2,y2)) print('{:-^40}'.format('輸出4')) print('x1={:>15.1f},y1={:>15.1f}'.format(x1,y1)) print('x2={:>15.1f},y2={:>15.1f}'.format(x2,y2))

對應輸出

第三部分

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:3}') print(40*'=')

對應輸出

 我個人最喜歡用format,因為它使用比較簡單,更靈活。

面對更復雜的輸出範例在處理的時候更高效