天天看点

python字符串_Python字符串函数

python字符串_Python字符串函数

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

python字符串_Python字符串函数

点击蓝字

关注我们

1.format

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

(1)

直接使用{}

python字符串_Python字符串函数

(2)

在{}中使用位置参数1

python字符串_Python字符串函数

(3)

在{}中使用位置参数2

python字符串_Python字符串函数

(4)

{}中的更多格式

python字符串_Python字符串函数

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

python字符串_Python字符串函数
python字符串_Python字符串函数

2.join()

joins a list of strings with another string as a separator

python字符串_Python字符串函数

3.split

join的逆向

python字符串_Python字符串函数

4.replace()

replaces one substring in a string with another

python字符串_Python字符串函数

5.startwith, endwith

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

python字符串_Python字符串函数

6.lower, upper

change the case of a string

python字符串_Python字符串函数

极客·Geek社团

python字符串_Python字符串函数

扫二维码

python字符串_Python字符串函数

关注我们

图文编辑|李如月

图文排版|李如月

审核    | 张旭

继续阅读