Python Split函数的用法总结
来源:互联网 发布:bloom filter python 编辑:程序博客网 时间:2024/04/30 04:59
字符串的split用法
说明:
Python中没有字符类型的说法,只有字符串,这里所说的字符就是只包含一个字符的字符串!!!
这里这样写的原因只是为了方便理解,仅此而已。
由于敢接触Python,所以不保证以后还有没有其他用法,所以会在后面不断加入。。。
1.按某一个字符分割,如‘.’
1
str
=
(
'www.google.com'
)
2
print
str
3
str_split
=
str
.split(
'.'
)
4
print
str_split
结果如下:
2.按某一个字符分割,且分割n次。如按‘.’分割1次
1
str
=
(
'www.google.com'
)
2
print
str
3
str_split
=
str
.split(
'.'
,
1
)
4
print
str_split
3.按某一字符串分割。如:‘||’
1
str
=
(
'WinXP||Win7||Win8||Win8.1'
)
2
print
str
3
str_split
=
str
.split(
'||'
)
4
print
str_split
结果如下:
4.按某一字符串分割,且分割n次。如:按‘||’分割2次
1
str
=
(
'WinXP||Win7||Win8||Win8.1'
)
2
print
str
3
str_split
=
str
.split(
'||'
,
2
)
4
print
str_split
5.按某一字符(或字符串)分割,且分割n次,并将分割的完成的字符串(或字符)赋给新的(n+1)个变量。(注:见开头说明)
如:按‘.’分割字符,且分割1次,并将分割后的字符串赋给2个变量str1,str2
1
url
=
(
'www.google.com'
)
2
str1, str2
=
url.split(
'.'
,
1
)
3
print
str1
4
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()函数的用法
- java获取新浪天气预报代码
- 用三位转速计测量超低频率
- Hello world
- C# 使用zedgraph绘制 柱状图
- elasticsearch 查看集群统计信息
- Python Split函数的用法总结
- C#中的全局变量
- 用Python进行网络爬虫和数据分析的初次尝试(一)
- Android深入探究-- 实现即时拍照并上传
- 缴费金额按年排列
- 记录一个统计MSSQL TABLE资料量的sp
- 微信公共服务平台开发(.Net 的实现)
- cocos2dx 对全部动作或单个动作速度的改变
- js动态字符串拼接案例