python处理数据——去除字符串两端的引号
来源:互联网 发布:微信运动的数据来源 编辑:程序博客网 时间:2024/05/16 08:04
在用python处理数据,会出现获得的数据本身两端带有引号,而我们需要的是形如xxx,而不是“xxx”否则就会出现问题。比如:
『解决方法一:』
使用lstrip()和rsrtip()字符串函数
函数说明如下:
str.lstrip([chars])
Return a copy of the string with leading characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix; rather, all combinations of its values are stripped:
>>> ' spacious '.lstrip()'spacious '>>> 'www.example.com'.lstrip('cmowz.')'example.com'
str.rstrip([chars])
Return a copy of the string with trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a suffix; rather, all combinations of its values are stripped:
>>> ' spacious '.rstrip()' spacious'>>> 'mississippi'.rstrip('ipz')'mississ'
具体使用如下:
『解决方法二』
先把字符转换为列表,使用列表的remove函数,再把列表拼成字符串
函数说明如下:
array.remove(x)
Remove the first occurrence of x from the array.
但是remove(x)每次只能只能移除x在列表中出现的第一次!所以可能会有副作用,不过对于一个单词或者短语还是没有问题的。
具体使用如下:
总结:可能还有更多的方法(比如转换成列表可以定位后删除),以上两种方法应该可以应对较多情况。
- python处理数据——去除字符串两端的引号
- python 去除字符串两端的引号
- js 如何去除字符两端的引号
- 去除字符串两端的空格
- 去除字符串两端的字符
- 001_005 Python 去除字符串两端的空格
- javascript去除字符串两端空格的函数
- flex 中去除字符串两端的空格
- javascript去除字符串两端的空格
- Js去除字符串左右两端的空格
- 如何去除字符串两端的空格
- 通过stringByTrimmingCharactersInSet去除字符串两端的特殊符号
- javascript去除字符串左右两端的空格
- JS去除字符串左右两端的空格
- 去除字符串 两端的空格 功能
- ios 字符串去除两端的空白 字符串去除所有空白
- 去除字符串两端空格
- 去除字符串两端空格
- Java学习——JDK,JRE,JVM之间的联系
- 堆内存和栈内存
- Codeforces Round #371 (Div. 2) B. Filya and Homework(水题)
- Leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal 中序和后序恢复二叉树
- 20160916IOS音频开发之资源与元数据,解决获取资源属性问题(一)
- python处理数据——去除字符串两端的引号
- 商品添加和减少
- android自定义view 模仿win10进度条
- 计算机的组成及其功能
- Linux笔记--shell总结(2)
- Python函数式编程指南(三):迭代器
- C#(asp.net)哈希表
- 设计模式之状态模式
- File对象的创建