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 ...
随机推荐
- group()、start()、end()、span()
- 为Docker镜像添加SSH服务
一.基于commit命令创建 1. 首先下载镜像 $ docker run -it ubuntu:16.04 /bin/bash 2. 安装SSH服务 #更新apt缓存 root@5ef1d31632 ...
- js利用数组实现队列与堆栈效果
之前在写Android的时候,会用到很多的队列与堆栈方式,其实js利用数组可以简单的实现类似的效果. 队列实现 var queue = new Array(); // unshift() 方法可向数组 ...
- Emgu cv3.0.0 图像收集
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- 【摘自张宴的"实战:Nginx"】nginx配置
user nobody;worker_processes 2; #error_log logs/error.log;error_log logs/error.log notice;#error_log ...
- cmake 编译安装方法
cmake版本3.7.2 1.根目录下./bootstrap 2.make 3.sudo make install
- (转)C++中使用C代码
昨晚看书的时候碰到一个问题,在C++中如何调用C代码...于是查了一下资料...发现了一个大神写的文章挺好的. -------------------------------------------- ...
- rest-framework组件 之 认证与权限组件
浏览目录 认证组件 权限组件 频率组件 认证与权限组件 认证组件 局部视图认证 在app01.service.auth.py: class Authentication(BaseAuthenticat ...
- HUB和Switch
http://baike.baidu.com/view/600161.htm 当然交换机的功能还不止如此,它可以把网络拆解成网络分支.分割网络数据流,隔离分支中发生的故障,这样就可以减少每个网络分支的 ...
- GitHub Pages搭建博客HelloWorld版
1.原理 GitHub作为博客相关文件的托管方,你把按照jekyll规定的目录及文件上传至github库中,通过约定的库名称即可访问到经过jekyll渲染后的博客页面. 2.搭建过程 2.1.注册Gi ...