Python 字符串操作 starswitch() find() re.IGNORECASE replace() join()
检测开头&结尾
开头:startswith()
url = 'http://www.python.org'
url.startswith('http')
>>>True
结尾:endswith()
url = 'http://www.python.org'
url.endswith('org')
>>>True
筛选多个结果
url = 'http://www.python.org'
choices = ('ogr', 'com')
url.endswith(choices)
>>>True
寻找字符串:find()
string = "I am Etisan"
string.find("am")
>>>2
string.find("are")
>>>-1
忽略大小写:re.IGNORECASE
#导入re模块
import re
re.findall('i',string,flags=re.IGNORECASE)
>>>['I', 'i']
替换:replace()
string.replace('Etisan','ET')
>>>'I am ET'
忽略大小写
re.sub('Etisan','ET',string,flags=re.IGNORECASE)
>>>'I am ET'
合并拼接:join()
parts = ['I', 'am', 'Etisan']
''.join(parts)
>>>'IamEtisan'
' '.join(parts)
>>>'I am Etisan'
Python 字符串操作 starswitch() find() re.IGNORECASE replace() join()的更多相关文章
- Python 字符串操作
Python 字符串操作(string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分割等) 去空格及特殊符号 s.strip() .lstrip() .rstrip(',') 复制字符 ...
- python字符串操作实方法大合集
python字符串操作实方法大合集,包括了几乎所有常用的python字符串操作,如字符串的替换.删除.截取.复制.连接.比较.查找.分割等,需要的朋友可以参考下: #1.去空格及特殊符号 s.st ...
- 转 Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
转自: http://www.cnblogs.com/huangcong/archive/2011/08/29/2158268.html 黄聪:Python 字符串操作(string替换.删除.截取. ...
- Python 字符串操作及string模块使用
python的字符串操作通过2部分的方法函数基本上就可以解决所有的字符串操作需求: python的字符串属性函数 python的string模块 1.字符串属性方法操作: 1.>字符串格式输出对 ...
- Python字符串操作详解
菜鸟学Python第五天 流程控制 for循环 while循环 VS for循环: while循环:称之为条件循环,循环的次数取决于条件何时为false for循环:称之为迭代器循环,循环的次数取决于 ...
- 『无为则无心』Python序列 — 17、Python字符串操作常用API
目录 1.字符串的查找 @1.find()方法 @2.index()方法 @3.rfind()和rindex()方法 @4.count()方法 2.字符串的修改 @1.replace()方法 @2.s ...
- [转]Python 字符串操作实现代码(截取/替换/查找/分割)
原文地址:http://www.jb51.net/article/38102.htm ps:好久没更新python代码了,这次用到了字符串,转来看看 Python 截取字符串使用 变量[头下标:尾下标 ...
- python字符串操作总结
python中有各种字符串操作,一开始python有个专门的string模块,要使用需先import string.后来从python2.0开始,string方法改用str.method()形式调用, ...
- python 字符串操作常用函数总结
说明:并不完善,只是记录自己使用到的,没使用到或会用的不会出现在本文. 1.字符串截取 (1)基于索引 s = 'ilovepython' s[0]='i' s[-1] = 'n' (2)取其中一段 ...
随机推荐
- sybase central 报 NullPointerException 解决
准备发布版本,但是要创建数据库的时候遇到了问题,发现之前可以正常打开的sybase Central 现在无法打开了.苦恼一段时间后找到如下解决方法. 报错如下: 解决如下: 正常打开:
- Python中的__init__和__new__
一.__init__ 方法是什么? 使用Python写过面向对象的代码的同学,可能对 __init__ 方法已经非常熟悉了,__init__ 方法通常用在初始化一个类实例的时候.例如: # -*- c ...
- Laravel使用心得
Laravel使用心得 1.session使用 laravel的session使用时,不要使用exit和die,否则session会为空. 2.ajax提交注意框架对post的CSRF保护 在头加上& ...
- 在docker中安装mysql
#!/bin/sh # 安装docker # 在docker中安装mysql # 解决了docker容器中无法输入中文的问题 ##########################安装docker # ...
- phpMyAdmin 4.8.x 本地文件包含漏洞利用
phpMyAdmin 4.8.x 本地文件包含漏洞利用 今天ChaMd5安全团队公开了一个phpMyAdmin最新版中的本地文件包含漏洞:phpmyadmin4.8.1后台getshell.该漏洞利用 ...
- python mysql 单表查询 多表查询
一.外键 变种: 三种关系: 多对一 站在左表的角度: (1)一个员工 能不能在 多个部门? 不成立 (2)多个员工 能不能在 一个部门? 成立 只要有一个条件成立:多 对 一或者是1对多 如果两个条 ...
- linux更换jdk版本
参考:https://blog.csdn.net/meilin_ya/article/details/80650945 1.将两个版本的jdk放到linux环境2.设置选择使用alternatives ...
- c++函数strapy
头文件:#include <string.h> 定义函数:char *strcpy(char *dest, const char *src); 函数说明:strcpy()会将参数src 字 ...
- 如何关闭git pull产生的merge 信息
编辑 ~/.gitconfig [core] mergeoptions = --no-edit 或者终端之行 git config --global core.mergeoptions --no-ed ...
- oracleDB python chines_miscode
oracle account lock: solutionhttp://www.cnblogs.com/jianqiang2010/archive/2011/09/01/2162574.html li ...