字符串函数
“x”+“y” | 连接两个字符串 |
---|
“x"n或n"x” | 将x复制n次 |
"x"ins | 如果x是s的子串,返回为Ture,否返回False |
>>> "ab" in"abdf"
True
字符串处理函数
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/fba4da699018c9185f8eda592d8facc8.jpeg)
>>> chr(65)
'A'
>>> ord("A")
65
>>> hex(17)
'0x11'
>>> oct(9)
'0o11'
字符串处理方法
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9393927fbeac756927722b4720ec2dc2.jpeg)
>>> a="ABC"
>>> a.lower()
'abc'
>>> "OKK".lower()
'okk'
>>> a="dfefhytk"
>>> a.split()
['dfefhytk']
>>> a="df efh ytk"
>>> a.split()
['df', 'efh', 'ytk']
>>> a="df fgrth fg"
>>> a.split("f")
['d', ' ', 'grth ', 'g']
>>> a="df fgrth fg"
>>> a.split("g")
['df f', 'rth f', '']
>>> type(a)
<class 'str'>
>>> type(a.split())
<class 'list'>
>>> "333565645".count("56")
2
>>> "abcdefg".replace("cd","**")
'ab**efg'
>>> "abcdefg".replace("ab","**")
'**cdefg'
>>> "*".join("3457")
'3*4*5*7'
>>>