python字符串函数strip()
来源:互联网 发布:设计模式 php 编辑:程序博客网 时间:2024/06/05 16:23
在做接口压力测试参数化请求参数时,使用readlines()读取txt文档,发现有\n换行符号。通过查阅资料发现字符串的strip()方法可以去掉字符串中头部和尾部指定字符。
语法:
str.strip([chars])
作用:
Python的strip()方法用于移除字符串头部、尾部指定字符,默认是空格。返回一个新的字符串。
处理实例:
with open(".pe.txt") as f1: type_ = f1.readlines()# readlines()方法读取字符串所有line保存为一个list# join()方法将list转为字符串。在使用字符串的strip()去掉\n。type1 = ','.join(type_).strip('\n')# 重新将字符串变为list,通过分割字符串,重新变为list。type2 = type1.split(',')join()函数list等转字符串
语法: 'sep'.join(seq)
参数说明
sep:分隔符。可以为空
seq:要连接的元素序列、字符串、元组、字典
上面的语法即:以sep作为分隔符,将seq所有的元素合并成一个新的字符串
返回值:返回一个以分隔符sep连接各个元素后生成的字符串
阅读全文
0 0
- python字符串函数strip()
- Python的字符串处理函数strip()
- python 字符串之strip
- python strip()函数 介绍
- python strip()函数 介绍
- python strip()函数
- python中的strip函数
- python strip()函数 介绍
- python strip()函数
- Python的strip函数
- python strip()函数
- python strip() split()函数
- python strip()函数
- python strip()函数
- python strip()函数
- python strip()函数
- python strip()函数
- python strip()函数
- 定时向指定邮箱发送邮件
- 冒泡排序
- 计算圆周率
- String类
- Zookeeper系列(一)
- python字符串函数strip()
- js实现集合方法
- 单例的两种类型,以及介绍
- The study of Class and Instance in Python(20170918)
- LeetCode 80. Remove Duplicates from Sorted Array II
- 洛谷 1533 可怜的狗狗
- Elasticsearch5.6.0安装ik分词器
- JQuery学习笔记2
- ipcs ipcrm命令详解