python中的字符串操作
#!/usr/bin/python
# -*- coding: UTF-8 -*- '''
str.capitalize()
'''
str = 'this is a string example'
print str.capitalize() '''
str.center(width[, fillchar])
'''
str = ''
print str.center(10, '') '''
str.count(sub, start=0, end=len(string))
'''
str = '123abc123'
print str.count('') '''
str.decode(encoding='utf-8', errors='strict')
'''
str = ''
print str.encode('base64', 'strict') '''
str.encode(encoding='utf-8', errors='strict')
'''
str = 'MTIz'
print str.decode('base64', 'strict') '''
str.endswith(suffix[, start[, end]])
'''
str = '123abc'
print str.endswith('abc', 0, len(str)) '''
str.expandtabs(tabsize=8)
'''
str = "this is\t a example"
print str.expandtabs(8) '''
str.find(str, beg=0, end=len(string))
'''
str = ''
print str.find('') '''
str.index(str, beg=0, end=len(string))
只不过如果str不在string中会报一个异常
'''
str = ''
print str.index('') '''
str.isalnum()
'''
str = 'abc123'
print str.isalnum() '''
str.isalpha()
'''
str = 'abc123'
print str.isalpha() '''
str.isdigit()
'''
str=''
print str.isdigit() '''
str.islower()
'''
str = 'abc'
print str.islower() '''
str.isupper()
'''
str = 'BASIC SEARCH'
print str.isupper() '''
str.isnumeric()
这种方法只针对unicode对象
'''
str = u"this2009"
print str.isnumeric() '''
str.isspace()
'''
str = '\t'
print str.isspace() '''
str.istitle()
'''
str = 'This Is Example'
print str.istitle() '''
str.join(sequence)
'''
str = '-'
seq = ['a', 'b', 'c']
print str.join(seq) '''
str.ljust(width[, fillchar])
'''
str = 'abc'
print str.ljust(10, '-')
print str.rjust(10, '-') '''
str.lower()
'''
str = 'THIS is example'
print str.lower() '''
str.lstrip([chars])
'''
str = '123abc123'
print str.lstrip('')
print str.rstrip('')
print str.strip('') '''
maketrans(intab, outtab)
创建字符映射的转换表
'''
#print maketrans('abc', '123') '''
max(str)
返回字符串中最大的字母
'''
str = 'abc'
print max(str) '''
min(str)
返回字符串中最小的字母
'''
str = 'abc'
print min(str) '''
str.partition(str)
根据指定字符进行分割 返回三元的元组
'''
str='a|b|c'
print str.partition('|') '''
str.replace(old, new[, max])
'''
str = 'abc123abc'
print str.replace('', 'abc', 1) '''
str.split(str="", num=string.count(str))
'''
str = 'a|b|c'
print str.split('|') '''
str.splitlines(num = string.count('\n'))
按照行进行分割
'''
str = "line1-a b c\nline2- 1 2 3"
print str.splitlines(0) '''
str.startwith(str, beg = 0, end = len(str))
'''
str = 'a123'
print str.startswith('a') '''
str.swapcase()
'''
str = 'this is example A'
print str.swapcase() '''
str.title()
'''
str = 'this is example'
print str.title() '''
str.translate(table[, deletechars])
'''
trantab = {
'':'a',
'':'b',
'':'c'
}
str = '123abc'
#print str.translate(trantab) '''
str.upper()
'''
python中的字符串操作的更多相关文章
- Python中的字符串操作总结(Python3.6.1版本)
Python中的字符串操作(Python3.6.1版本) (1)切片操作: str1="hello world!" str1[1:3] <=> 'el'(左闭右开:即是 ...
- 一句python,一句R︱python中的字符串操作、中文乱码、NaN情况
一句python,一句R︱python中的字符串操作.中文乱码.NaN情况 先学了R,最近刚刚上手Python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句pytho ...
- 一句python,一句R︱python中的字符串操作、中文乱码
先学了R,最近刚刚上手python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句python,对应写一句R. pandas可谓如雷贯耳,数据处理神器. 以下符号: = ...
- java入门学习笔记之2(Java中的字符串操作)
因为对Python很熟悉,看着Java的各种字符串操作就不自觉的代入Python的实现方法上,于是就将Java实现方式与Python实现方式都写下来了. 先说一下总结,Java的字符串类String本 ...
- python中的字符串
一.在python中,字符串是不可变类型 通过以下代码说明: >>> s = 'hello, world' >>> id(s) 2108634288304 > ...
- 【转】Python中的字符串与字符编码
[转]Python中的字符串与字符编码 本节内容: 前言 相关概念 Python中的默认编码 Python2与Python3中对字符串的支持 字符编码转换 一.前言 Python中的字符编码是个老生常 ...
- Python中通过open()操作文件时的文件中文名乱码问题
最近在用Python进行文件操作的时候,遇到创建中文文件名的乱码问题. Python默认是不支持中文的,一般我们在程序的开头加上#-*-coding:utf-8-*-来解决这个问题,但是在我用open ...
- python中OS模块操作文件和目录
在python中执行和操作目录和文件的操作是通过内置的python OS模块封装的函数实现的. 首先导入模块,并查看操作系统的类型: >>> import os os.name # ...
- Python中的json操作
Python中的json操作 标签(空格分隔): python 编码 json 字符串前缀问题 字符串前缀可以有r,u r:表示原始(raw)字符串,比如'\n'不会被转义.常用于正则. u:表示un ...
随机推荐
- android 浅谈Aidl 通讯机制
服务端: 首先是编写一个aidl文件,注意AIDL只支持方法,不能定义静态成员,并且方法也不能有类似public等的修饰符:AIDL运行方法有任何类型的参数和返回值,在java的类型中,以下的类型使用 ...
- 【代码笔记】iOS-截屏功能
代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // ...
- 【读书笔记】iOS网络-使用Bonjour实现自组织网络
Bonjour就是这样一种技术:设备可以通过它轻松探测并连接到相同网络中的其他设备,整个过程只需要很少的用户参与或是根本就不需要用户参与.该框架提供了众多适合于移动的使用场景,如基于网络的游戏,设备间 ...
- 【读书笔记】iOS网络-解析响应负载
Web Service可以通过多种格式返回结构化数据, 不过大多数时候使用的是XML与JSON.也可以让应用只接收HTML结构的数据.实现了这些Web Service或是接收HTML文档的应用必须能解 ...
- 【Android】用MediaRecorder录制视频太短崩的问题
具体表现: 调用MediaRecorder的start()与stop()间隔不能小于1秒(有时候大于1秒也崩),否则必崩. 错误信息: java.lang.RuntimeException: stop ...
- Swfit 字符与字符串
Swfit 字符与字符串 OC 定义字符 char charValue = 'a'; Swift 定义字符 var charValue:Character = "a" Unicod ...
- OC 多态
OC 多态 多态的概念 没有继承,就没有多态 不同类的对象能够定义相同名称的方法 当父类对象的指针或引用指向子类对象时,会进行动态监测,调用真实的方法 C++只有虚函数才能实现多态,OC中所有方法都可 ...
- MonoDevelop几个常用的快捷键
MonoDevelop几个常用的快捷键 CTRL+K 删除光标所在行的该行后面的代码 CTRL + ALT +C 注释/不注释该行 CTRL+ DOWN 像鼠标滚轮一样向下拖 CTRL + UP ...
- Winform读写App.config文件以及重启程序
//重启主程序 //System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Locatio ...
- Linux:U盘安装Linux系统
前天一个同学找我帮忙安装Linux系统,没有光盘,也不想在虚拟机里安装,在此情况下,我就采用U盘方式来安装Linux系统了.又想到还有其他人可能也不会 使用U盘安装系统,这里就作一个简单的介绍. 1. ...