Python中一道关于字符串分割的题目
2017-12-05 19:57
447 查看
Python中一道字符串题目:
例如
常用分割字符串的方法split(),查看split()方法的源码
其中这句话If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result.当sep任何参数不给时将默认以任何空格和空白分割,而tab就是4个空格,因而直接用split()方法就可以了
(面试题)给定一个字符串aStr,返回使用空格或者'\t'分割后的倒数第二个子串
例如
testStr = 'I have \t one \tdream!' resultStr = testStr.split() print(resultStr) print(resultStr[-2])
常用分割字符串的方法split(),查看split()方法的源码
def split(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__ """ S.split(sep=None, maxsplit=-1) -> list of strings Return a list of the words in S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result. """ return []
其中这句话If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result.当sep任何参数不给时将默认以任何空格和空白分割,而tab就是4个空格,因而直接用split()方法就可以了
相关文章推荐
- 一道微软面试时碰到的,经典的,关于字符串操作的面试题目
- 关于js字符串替换的一道笔试题目
- java 一道关于String字符串操作题目
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- python 按照固定长度分割字符串的方法小结
- Python 字符串操作(截取/替换/查找/分割)
- 关于金山的一道面试题目
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 字符串循环右移的一道题目
- 读取文件行并分割行中字符串:C/C++以及python实现
- 一道关于c++拷贝构造与=运算符的题目
- 一道关于逆序对的题目
- 一道C#字符串的题目
- The internals of Python string interning(关于字符串is比较两个字符串对象的深度解析)
- Python中通过多个字符分割(split)字符串的方法--转载
- 黑马程序员---关于取出一个字符串中字母个数的题目分析
- 小甲鱼python视频弟十二讲(关于字符串的方法及注释上)
- 【python系列】Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 一道关于集合分组并进行笛卡尔积的题目思路
- 转 Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)