当前位置:  首页>> 技术小册>> Python合辑3-字符串用法深度总结

str.zfill(width)

zfill 方法用 0 前缀填充字符串以获得指定的宽度。例如:

  1. example = "0.8" # len(example) is 3
  2. example_zfill = example.zfill(5) # len(example_zfill) is 5
  3. print(example_zfill)

Output:
```
000.8


该分类下的相关小册推荐: