Python 官方文档:入门教程 => 点击学习
yuan@ThinkPad-SL510:~$ ipython -nobanner In [1]: comma_delim_string = "pos1,pos2,pos3" In [2]: pipe_delim_stri
- yuan@ThinkPad-SL510:~$ ipython -nobanner
-
- In [1]: comma_delim_string = "pos1,pos2,pos3"
-
- In [2]: pipe_delim_string = "pipepos1|pipepos2|pipepos3"
-
- In [3]: co
- coerce compile continue
- comma_delim_string complex copyright
按Tab会智能补全的不仅仅是iPython哦,去试试,告诉不了解的童鞋
- In [3]: comma_delim_string.split(",")
- Out[3]: ['pos1', 'pos2', 'pos3']
-
- In [4]: pipe_delim_string.sp
- pipe_delim_string.split pipe_delim_string.splitlines
-
- In [4]: pipe_delim_string.split("|")
- Out[4]: ['pipepos1', 'pipepos2', 'pipepos3']
split()方法的典型用法即是把希望作为分割符的字符串(注意:是字符串,不一定是一个)传给它。
- yuan@ThinkPad-SL510:~$ ipython -nobanner
-
- In [1]: two_field_string ="8675890,This is a freefORM, plain text, string"
-
- In [2]: two_field_string.spli
- two_field_string.split two_field_string.splitlines
-
- In [2]: two_field_string.split(',',1)
- Out[2]: ['8675890', 'This is a freeform, plain text, string']
-
- In [3]: two_field_string.split(',',2)
- Out[3]: ['8675890', 'This is a freeform', ' plain text, string']
- yuan@ThinkPad-SL510:~$ ipython -nobanner
-
- In [1]: mixed_case_string = "VOrpal BUnny"
-
- In [2]: mixed_case_string == "vorpal bunny"
- Out[2]: False
-
- In [3]: mixed_case_string.lower() == "vorpal bunny"
- Out[3]: True
-
- In [4]: mixed_case_string == "VORPAL BUNNY"
- Out[4]: False
-
- In [5]: mixed_case_string.upper() == "VORPAL BUNNY"
- Out[5]: True
upper()和lower()并不是简单的返回字符串的大写和小写,它在字符串的比较上有很大作用,想到了吧?呵呵
--结束END--
本文标题: Python -- 操作字符串[2/3]
本文链接: https://www.lsjlt.com/news/191611.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0