三種方式:
name = 'Tom'
age = 30
height = 170.8
print('hi %s' % (name))
print('年齡: %d' % (age))
print('身高: %f' % (height))
name = 'Tom'
age = 30
height = 170.8
print('hi {}'.format(name))
print('年齡: {}'.format(age))
print('身高: {}'.format(height))
- python版本 > 3.6
name = 'Tom'
age = 30
height = 170.8
print(f'hi {name}')
print(f'年齡: {age}')
print(f'身高: {height}')
若是想印出固定字元
可以使用 >(往右邊對齊) , < (往左邊對齊)符號
name1 = 'Tom'
name2 = 'Larry'
print(f'hi {name1:<8}!!') #hi Tom !!
print(f'hi {name2:<8}!!') #hi Larry !!