Python Split函数的用法总结
来源:互联网 发布:软件 po 编辑:程序博客网 时间:2024/05/16 14:13
字符串的split用法
说明:
Python中没有字符类型的说法,只有字符串,这里所说的字符就是只包含一个字符的字符串!!!
这里这样写的原因只是为了方便理解,仅此而已。
由于敢接触Python,所以不保证以后还有没有其他用法,所以会在后面不断加入。。。
1.按某一个字符分割,如‘.’
1
2
3
4
str
=
(
'www.google.com'
)
print
str
str_split
=
str
.split(
'.'
)
print
str_split
结果如下:
2.按某一个字符分割,且分割n次。如按‘.’分割1次
1
2
3
4
str
=
(
'www.google.com'
)
print
str
str_split
=
str
.split(
'.'
,
1
)
print
str_split
3.按某一字符串分割。如:‘||’
1
2
3
4
str
=
(
'WinXP||Win7||Win8||Win8.1'
)
print
str
str_split
=
str
.split(
'||'
)
print
str_split
结果如下:
4.按某一字符串分割,且分割n次。如:按‘||’分割2次
1
2
3
4
str
=
(
'WinXP||Win7||Win8||Win8.1'
)
print
str
str_split
=
str
.split(
'||'
,
2
)
print
str_split
5.按某一字符(或字符串)分割,且分割n次,并将分割的完成的字符串(或字符)赋给新的(n+1)个变量。(注:见开头说明)
如:按‘.’分割字符,且分割1次,并将分割后的字符串赋给2个变量str1,str2
1
2
3
4
url
=
(
'www.google.com'
)
str1, str2
=
url.split(
'.'
,
1
)
print
str1
print
str2
0 0
- Python Split函数的用法总结
- Python Split函数的用法总结
- Python Split函数的用法总结
- Python Split函数的用法总结
- Python Split函数的用法总结
- Python Split函数的用法总结
- Python Split函数的用法总结
- python strip()函数和Split函数的用法总结
- python strip()函数和Split函数的用法总结
- Python Split函数的用法
- 【python】Python中split函数的用法
- String的split()函数的用法总结
- python 中join 、split函数的用法
- Python中split函数的用法
- Python中的split()函数的用法
- Python中的split()函数的用法
- Python中的split()函数的用法
- 关于Python里split()函数的用法
- android Alarm闹钟发送广播播放音乐
- Android-->原生API搭建Android Http服务器
- C++ STL之deque详解
- 使用FreeMarker邮件模版来发送邮件
- hiho第三周——字符串匹配KMP算法
- Python Split函数的用法总结
- android studio常用快捷键整理
- 再温《HP大中华区总裁孙振耀退休感言》
- OGG目的端的checkpoint table被drop的修复方法
- WPF前后台资源相互调用的方法
- C++ 类型转换(Casting Operators)
- Ubuntu下is not in the sudoers file 问题解决
- Android获取电话号码的实例
- 东莞理工学院怎么样?