python字符串必知必会

本博文用以记录博主在学习or刷题中遇见的字符串常见骚操作,不定期更新or纠错。

1.str.split(’ ')

字符串拆分,以’ '为拆分依据

2.str.split(’ ')

去掉字符串前后的’ ’

3.str.join(迭代器)

将str夹在迭代器的各个内容中去。
示例:

word = ['a','b','c','d']
'o'.join( w for w in word)

结果:
aobocod

word = 'abcd'
'o'.join( word)

结果:
aobocod

4.大小写转换

str.upper()
str.lower()

4.字符串切片

与序列切片一致

猜你喜欢

转载自blog.csdn.net/weixin_44414593/article/details/106974563