Python -- 操作字符串[2/3]
短信预约 -IT技能 免费直播动态提醒
- 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()并不是简单的返回字符串的大写和小写,它在字符串的比较上有很大作用,想到了吧?呵呵
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341