Python中split的用法
来源:互联网 发布:java web获取项目路径 编辑:程序博客网 时间:2024/06/10 09:50
字符串的split用法
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】Python中split函数的用法
- Python中split用法
- Python中字符串的split用法
- python 中join 、split函数的用法
- python中join()和split()的用法
- Python中split函数的用法
- python 中join 和 split的用法
- Python中split函数用法
- python中Split函数用法
- Python Split函数的用法
- C# 中split的用法
- C# 中split的用法
- C# 中split的用法
- C# 中split的用法
- Java中split的用法
- C# 中split的用法
- C# 中split的用法
- 单片机和虚拟机Linux双向通信
- Android MediaPlayUtil 简单工具类
- Run monitoring physical devices on devstack
- How do I sort an integer array while also keeping identical elements apart from each other?
- Linux下的文件内容查阅
- Python中split的用法
- 银行卡BIN码大全
- LED恒流驱动芯片
- linux 查看当前用户id、whoami用户列表、用户组、用户权限/etc/passwd、/etc/group、/etc/shadow以及切换用户身份、su、sudo、/etc/sudoers
- ExpandableListView小结
- 1004. 成绩排名
- Core Data入门
- Mina框架学习笔记(一)
- DWR3.0框架入门(3) —— ScriptSession的维护及优化