需要知道的几个python字符串函数
点击蓝字
关注我们
1.format
字符串的format函数为非字符串对象嵌入字符串提供了一种非常强大的方法。在format方法中,字符串使用{}来代替一系列字符串的参数并规定格式。下面通过几个例子来详细解释其用法。
(1)
直接使用{}
(2)
在{}中使用位置参数1
(3)
在{}中使用位置参数2
(4)
{}中的更多格式
:<4表示左对齐占用四格位置,其结果为:
2.join()
joins a list of strings with another string as a separator
3.split
join的逆向
4.replace()
replaces one substring in a string with another
5.startwith, endwith
determine if there is a substring at the start and end of a string, respectively.
6.lower, upper
change the case of a string
极客·Geek社团
扫二维码
关注我们
图文编辑|李如月
图文排版|李如月
审核 | 张旭