python 字符串的特性
str字符判断大小写
url1 = 'http://www.cctv.com'
url2 = 'file:///mnt'
print url1.startswith('http') #找出字符是否以'...'开头
print url2.startswith('file') #找出字符串是否以'...'开头
print '123'.isdigit() #判断是否为数字
print '1a1'.isdigit() #判断是否为数字
print 'Hello'.istitle() #判断是否位标题,第一个字母大写,其余小写
print 'hello'.upper() #将小写转成大写
print 'HELLO'.lower() #将大写转换成小写
print 'hello'.islower() #判断是小写
print 'HELLoO'.isupper() #判断是大写
str字符串开头和结尾匹配
s = 'hello.jpg'
print s.endswith('.jpg')#找出字符串是否以...结尾
str字符串的分离和连接
分离
s = '172.25.254.250'
sl = s.split('.') #split对于字符串进行分离,分割符为'.'
连接
print '/'.join('hello') #连接符为‘/’
h/e/l/l/o
str字符串的特性
# 索引:0,1,2,3,4 索引值是从0开始
s = 'hello' #定义字符串
print s[0] #索引第0个字符,即“h”
print s[1] #索引第一个字符,即“e”
# 切片
# 切片的规则:s[start:end:step] 从start开始到end-1结束,步长:step
print s[0:3]
print s[0:4:2]
print s[:] # 显示所有字符
print s[:3] # 显示前3个字符
print s[::-1] # 对字符串倒叙输出
print s[1:] # 除了第一个字符以外,其他全部显示
print s * 10 # 重复10次
print 'hello ' + 'world' # 连接
# 成员操作符
print 'q' in s # 查找字符串中是否有‘q’,有则为“True”,没有则为“False”
str字符串的搜索和替换
s = 'hello world'
print len(*) #统计字符串中字符个数
print s.find('world') #find 找到字符串,并返回最小索引
print s.replace('hello','westos') #替换所指定的字符串
str字符串的统计
print ‘heelloo’.count('o') #统计字符串中有几个‘o’
python 字符串的特性的更多相关文章
- python字符串的特性及相关应用
一.字符串定义 字符串是 Python 中最常用的数据类型.用单引号(' '),双引号(" ")或者三引号(''' ''')括起来的数据称为字符串(其中,使用三引号的字符串可以横跨 ...
- python 字符串处理
介绍字符串相关的:比较,截取,替换,长度,连接,反转,编码,格式化,查找,复制,大小写,分割等操作 什么是字符串 字符串 字符串或串(String)是由数字.字母.下划线组成的一串字符.一般记为 s= ...
- Python之字符串的特性及常用方法
字符串的特性 索引: (索引是从0开始) s='hello'print(s[0])print(s[4])print(s[-1]) #拿出最后一个字符 hoo12345678截取s[start:stop ...
- (原创)Python字符串系列(1)——str对象
在本博客 <Python字符串系列> 中,将介绍以下内容: Python内置的str对象及操作 字符串的格式化 Python中的正则表达式 re模块 本文将介绍Python内置的 str ...
- 7.python字符串-内置方法分析
上篇对python中的字符串内置方法进行了列举和简单说明,但这些方法太多,逐一背下效率实在太低,下面我来对这些方法按照其功能进行总结: 1.字母大小写相关(中文无效) 1.1 S.upper() -& ...
- python 字符串探讨
本文内容基于python3 几乎所有有用的程序都会涉及到某些文本处理,不管是解析数据还是产生输出.字符串的学习是重点中的重点,这一节将重点关注文本的操作处理,比如提取字符串,搜索,替换以及解析等.大部 ...
- python字符串-内置方法用法分析
1.字母大小写相关(中文无效) 1.1 S.upper() -> string 返回一个字母全部大写的副本
- 关于python字符串连接的操作
python字符串连接的N种方式 注:本文转自http://www.cnblogs.com/dream397/p/3925436.html 这是一篇不错的文章 故转 python中有很多字符串连接方式 ...
- StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?
StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...
随机推荐
- Winform状态栏控件中Label靠右显示的方法
设计器: 代码: 在Form_Load事件中添加 : statusStripMain.LayoutStyle= ToolStripLayoutStyle.HorizontalStackWithOv ...
- day35-hibernate映射 04-Hibernate的一级缓存:一级缓存的存在
数据源:文件和数据库.从内存中获取,不用去数据库发送SQL语句查询了.缓存技术是hibernate的一个优化的手段.Session结束了,一级缓存就没了,就销毁了.SeesionFactory没了,二 ...
- [hdu3949]XOR(线性基求xor第k小)
题目大意:求xor所有值的第k小,线性基模板题. #include<cstdio> #include<cstring> #include<algorithm> #i ...
- 初阶html学习总结(一)(转)
一:颜色代码 如果你想使用某种颜色,取得它的颜色值即可.比如,您想改变某些文字的颜色,您可以使用下面的代码:<font color=#ffc060 size=2>改变#符号后的代码即可改变 ...
- session和cookie个字消除的方法
session消除的方法就是: session_destroy(); cookie消除的方法就是setcookie()函数的时间设为当前时间即可 if(isset($_COOKIE['adminId' ...
- go语言linux下安装
1.从http://golang.org/dl/下载最新版本的GO语言二进制档案包. 注意:根据操作系统和计算架构正确选择档案包 2.使用tar命令将档案包解压到/usr/local目录中.具体方法如 ...
- 算法Sedgewick第四版-第1章基础-006一封装输出(文件)
1. package algorithms.util; /*********************************************************************** ...
- R: 自动计算代码运行时间
################################################### 问题:代码运行时间 18.4.25 怎么计算代码的运行时间? 解决方案: ptm = pro ...
- Entity Framework Tutorial Basics(27):Update Entity Graph
Update Entity Graph using DbContext: Updating an entity graph in disconnected scenario is a complex ...
- 在centos上安装sequoaidb的php驱动
1:搭建PHP的运行环境 yum install httpd httpd-devel yum install php php-devel yum install php-gd php-imap p ...