python字符串_Python字符串函数

3073bcc482bd423eb5199ac8f888661b.gif

需要知道的几个python字符串函数

3073bcc482bd423eb5199ac8f888661b.gif

点击蓝字

关注我们

1.format

字符串的format函数为非字符串对象嵌入字符串提供了一种非常强大的方法。在format方法中,字符串使用{}来代替一系列字符串的参数并规定格式。下面通过几个例子来详细解释其用法。

(1)

直接使用{}

7899154ed2da0c792f409a14595f3972.png

(2)

在{}中使用位置参数1

546d69f03653890a3297b0f292fb43c8.png

(3)

在{}中使用位置参数2

dcd328a05942f7b84c4f9398a8c635d1.png

(4)

{}中的更多格式

9030655332354b9996f43a111a4c7e27.png

:<4表示左对齐占用四格位置,其结果为:

1a72f0bcabcbd88b15b441c056827c56.png 554e90f3eeaadb566b48ed0b21cd661c.gif

2.join()

joins a list of strings with another string as a separator

94d702b0f4869f3dabdff65269c2e158.png

3.split

join的逆向

14ab905eb1aa7320e717761e408d3dcb.png

4.replace()

replaces one substring in a string with another

14156119f2f277f10776733ed66bfc5e.png

5.startwith, endwith

determine if there is a substring at the start and end of a string, respectively.

4c4930b4256cf7f497850b7cc43c02e5.png

6.lower, upper

change the case of a string

742f63819508dbb81d2eb6051044b046.png

极客·Geek社团

b9a2b93e42dd92ea39cac8b47b88618a.png

扫二维码

22f441e687e50f69d861c75020ec813d.png

关注我们

图文编辑|李如月

图文排版|李如月

审核    | 张旭

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值