- 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()并不是简单的返回字符串的大写和小写,它在字符串的比较上有很大作用,想到了吧?呵呵