整數格式化
- 請格式化一個整數,按10位輸出,不足10位前面補0
n = 1234
print(format(n, '10d'))
print(format(n, '0>10d'))
print(format(n, '0<10d'))
1234
0000001234
1234000000
浮點數格式化
x1 = 1234.5678
x2 = 58.1
print(format(x1, '0.2f'))
print(format(x2, '0.2f'))
1234.57
58.10
3. 請描述format 函數的主要用法
print(format(x2, '*>12.2f'))
print(format(x2, '*<12.2f'))
print(format(x2, '*^12.2f'))
print(format(123455678, ','))
print(format(123456.12321, ',.2f'))
print(format(x1, 'e'))
print(format(x1, '0.2E'))
*******58.10
58.10*******
***58.10****
123,455,678
123,456.12
1.234568e+03
1.23E+03
9 - python 字符串操作