python中strip、startswith、endswith
strip(rm)用来删除元素内的空白符:
rm对应要删除空白符的元素,当rm为空(strip())时删除所有元素的空白符
startswith、endswith用来查找开头或结尾条件的元素
例子:

1 li = ["alec", " aric", "Alex", "Tony", "rain"]
2 tu = ("alec", " aric", "Alex", "Tony", "rain")
3 dic = {'k1': "alex", 'k2': ' aric', "k3": "Alex", "k4": "Tony"}
4 for i in li:
5 b = i.strip()
6 if (b.startswith("a") or b.startswith("A")) and b.endswith("c"):
7 print(b)
8
9 for i in tu:
10 b = i.strip()
11 if (b.startswith("a") or b.startswith("A")) and b.endswith("c"):
12 print(b)
13
14 for i in dic:
15 b = dic[i].strip()
16 if (b.startswith("a") or b.startswith("A")) and b.endswith("c"):
17 print(b)

上面代码:查找以 a或A开头并且以 c 结尾的所有元素,并输出
输出结果:
alec
aric
alec
aric
aric
python中strip、startswith、endswith的更多相关文章
- Python中的startswith和endswith函数使用实例
Python中的startswith和endswith函数使用实例 在Python中有两个函数分别是startswith()函数与endswith()函数,功能都十分相似,startswith()函数 ...
- python中strip,lstrip,rstrip简介
一.起因 今天在做角色控制中,有一个地方用到rstrip,判断用户请求的url是否与数据库对应可用权限中url相符. if request.path == x.url or request.path. ...
- Python中strip方法的妙用
[开胃小菜] 当提到python中strip方法,想必凡接触过python的同行都知道它主要用来切除空格.有下面两种方法来实现. 方法一:用内置函数 #<python> if __name ...
- python中strip函数的用法
python中往往使用剥除函数strip()来对用户的输入进行清理.strip函数的最一般形式为: str.strip('序列') 其中,序列是一段字符串,该函数表示从头或者从尾部开始进行扫描,如果扫 ...
- Python中strip()、lstrip()、rstrip()函数的用法
Python中使用函数strip().lstrip().rstrip()来剔除字符串前后的特定字符 函数语法为:str.strip(chars) 返回值是一个新的字符串,不更改源字符串 其中,参数ch ...
- Python中strip()函数
在python API中这样解释strip()函数:
- python中strip()方法学习笔记
Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 当使用strip('xxx'),只要字符串头尾有"xxx"中的一个,就会去掉,而不是符合字符串''x ...
- 【Python】PYTHON中STRIP()方法学习笔记
Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 当使用strip('xxx'),只要字符串头尾有"xxx"中的一个,就会去掉,而不是符合字符串''x ...
- Python中strip()、lstrip()、rstrip()用法详解
Python中有三个去除头尾字符.空白符的函数,它们依次为: strip: 用来去除头尾字符.空白符(包括\n.\r.\t.' ',即:换行.回车.制表符.空格)lstrip:用来去除开头字符.空白符 ...
随机推荐
- javascript 判断是否移动客户端 userAgent isMobile
var isMobile = { Android: function () { return (/android/i.test(navigator.userAgent.toLowerCase())); ...
- 值得收藏的JSP连接mysql数据库的例子
1:用mysql驱动把mysql与tomcat的连接起来.把mysql驱动包(不用解压)放到Tomcat安装目录中lib文件夹下即可. 2:然后在自己的新建的web应用程序上面就可以下下面的代码 3: ...
- LeetCode——10. Regular Expression Matching
一.题目链接:https://leetcode.com/problems/regular-expression-matching/ 二.题目大意: 实现一个正则表达式,该正则表达式只有两种特殊的字符— ...
- javase每天内容总结(32期)
第一天 环境变量 编译与运行 dos命令 第二天 数据类型 运算符(三元) 第三天 引用数据类型(Scanner和Random) 流程控制语句 第四天 数组 第五天 方法(重载) 第六天 类 Arra ...
- csrf攻击 使用js 调用 php文件的方法(还没实践)
https://www.cnblogs.com/Im-Victor/p/9306535.html
- Hive格式各种格式下不同压缩算法的比较
原始Text格式的hive分区大小为119.2G. 压缩算法 Text格式 Parquet格式 ORC RCFile 不压缩 119.2G 54.1G 20.0G 98G Snappy压缩 30.2 ...
- 1118 Birds in Forest (25 分)
1118 Birds in Forest (25 分) Some scientists took pictures of thousands of birds in a forest. Assume ...
- [UE4]制作缩略图
一.创建一个专门用来做缩略图的角色CameraCharacter,不需要实体模型. 二.Auto Possess Player设置为“Player 0” 三.重力比例改成0(这样在天上的时候就不会往下 ...
- [UE4]GameMode、GameInstance、GameState、PlayerState、PlayerController
一.只有PlayerController和Pawn/Character才有输入事件(键盘.鼠标等等),PlayerState没有输入事件. 二.对于需要跨域关卡的数据信息,根据上图所知需要放到Game ...
- [UE4]声音系统概述
一.只能使用wav格式的声音 二.wav声音可以直接播放到打开的UE4编辑器内打开的Content文件夹.也可以直接导入 三.在Content中的文件夹的声音资源可以直接拖放到场景中,会以3D场景声音 ...