博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python zfill_Python字符串zfill()
阅读量:2532 次
发布时间:2019-05-11

本文共 1177 字,大约阅读时间需要 3 分钟。

python zfill

Python String zfill()

Python String zfill()

Python字符串zfill()

Python String zfill(width) function returns a new string of specified width. The string is filled with 0 on the left side to create the specified width.

Python字符串zfill(width)函数返回指定宽度的新字符串。 该字符串在左侧用0填充以创建指定的宽度。

If the string starts with sign characters (+,-) then the padding is done after the sign. If the specified width is less than the original string, then the original string is returned.

如果字符串以符号字符(+,-)开头,则在符号之后进行填充。 如果指定的宽度小于原始字符串,则返回原始字符串。

Python字符串zfill() (Python String zfill())

Let’s look at some examples of zfill() function.

让我们看一下zfill()函数的一些示例。

s = '100'print(s.zfill(6))s = '+100'print(s.zfill(6))s = '-100'print(s.zfill(6))

Output:

输出:

000100+00100-00100

Let’s see what happens when the specified width is smaller than the string length.

让我们看看当指定的宽度小于字符串长度时会发生什么。

s = '+100'print(s.zfill(3))

Output: +100

输出: +100

This function is useful when the string is numeric in nature. However, it works with any non-numeric string too.

当字符串本质上是数字时,此功能很有用。 但是,它也适用于任何非数字字符串。

s = 'abc'print(s.zfill(6))s = '+abc'print(s.zfill(6))

Output:

输出:

000abc+00abc
. 签出更多Python示例。

Official Documentation:

官方文档:

翻译自:

python zfill

转载地址:http://elmzd.baihongyu.com/

你可能感兴趣的文章
小D课堂 - 新版本微服务springcloud+Docker教程_3-07 Eureka服务注册中心配置控制台问题处理...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_4-01 常用的服务间调用方式讲解
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_4-02 微服务调用方式之ribbon实战 订单调用商品服务...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_4-03 高级篇幅之Ribbon负载均衡源码分析实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_4-06 Feign核心源码解读和服务调用方式ribbon和Feign选择...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_4-05 微服务调用方式之feign 实战 订单调用商品服务...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-02 Netflix开源组件断路器
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-01分布式核心知识之熔断、降级
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-04 feign结合hystrix断路器开发实战下...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-03 feign结合hystrix断路器开发实战上...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_6-01 微服务网关介绍和使用场景
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-05熔断降级服务异常报警通知
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_6-03 高级篇幅之zuul常用问题分析
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-08 断路器监控仪表参数
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_6-02 springcloud网关组件zuul
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-1.快速搭建SpringBoot项目,采用Eclipse...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_1-4.在线教育后台数据库设计...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-3.热部署在Eclipse和IDE里面的使用...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_1-3.在线教育站点需求分析和架构设计...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-4.后端项目分层分包及资源文件处理...
查看>>