#!/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中的字符串操作的更多相关文章

  1. Python中的字符串操作总结(Python3.6.1版本)

    Python中的字符串操作(Python3.6.1版本) (1)切片操作: str1="hello world!" str1[1:3] <=> 'el'(左闭右开:即是 ...

  2. 一句python,一句R︱python中的字符串操作、中文乱码、NaN情况

    一句python,一句R︱python中的字符串操作.中文乱码.NaN情况 先学了R,最近刚刚上手Python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句pytho ...

  3. 一句python,一句R︱python中的字符串操作、中文乱码

    先学了R,最近刚刚上手python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句python,对应写一句R. pandas可谓如雷贯耳,数据处理神器. 以下符号: = ...

  4. java入门学习笔记之2(Java中的字符串操作)

    因为对Python很熟悉,看着Java的各种字符串操作就不自觉的代入Python的实现方法上,于是就将Java实现方式与Python实现方式都写下来了. 先说一下总结,Java的字符串类String本 ...

  5. python中的字符串

    一.在python中,字符串是不可变类型 通过以下代码说明: >>> s = 'hello, world' >>> id(s) 2108634288304 > ...

  6. 【转】Python中的字符串与字符编码

    [转]Python中的字符串与字符编码 本节内容: 前言 相关概念 Python中的默认编码 Python2与Python3中对字符串的支持 字符编码转换 一.前言 Python中的字符编码是个老生常 ...

  7. Python中通过open()操作文件时的文件中文名乱码问题

    最近在用Python进行文件操作的时候,遇到创建中文文件名的乱码问题. Python默认是不支持中文的,一般我们在程序的开头加上#-*-coding:utf-8-*-来解决这个问题,但是在我用open ...

  8. python中OS模块操作文件和目录

    在python中执行和操作目录和文件的操作是通过内置的python OS模块封装的函数实现的. 首先导入模块,并查看操作系统的类型: >>> import os os.name # ...

  9. Python中的json操作

    Python中的json操作 标签(空格分隔): python 编码 json 字符串前缀问题 字符串前缀可以有r,u r:表示原始(raw)字符串,比如'\n'不会被转义.常用于正则. u:表示un ...

随机推荐

  1. 工作中碰到的js问题(disabled表单元素不能提交到服务器)

    今天碰到一个奇葩的问题,asp页面表单提交后,有一个文本框<input type="text" name="phone" id="phone&q ...

  2. fir终端打包,亲测可用

    1.注册fir.拿到token 2.安装 fir-cli 使用 Ruby 构建, 无需编译, 只要安装相应 gem 即可. $ ruby -v # > 1.9.3 $ gem install f ...

  3. iOS 为视图添加抖动效果

    抖动效果在开发中比较少用到,不过有时使用了确有个很好的装逼效果,用的时候就例如一些用户错误操作之类的 效果如下,不过gif看到的效果没实际的好看 上代码 - (void)shakeAnimationF ...

  4. android + red5 + rtmp

    背景:在已有的red5服务器环境下实现android客户端的视频直播 要实现客户端视频直播就先先对服务器端有所了解 Red5流媒体服务器是Adboe的产品,免费并且是开源的,与Flash搭配的时候可谓 ...

  5. HTML基础(一)——一般标签、常用标签和表格

    第一部分  HTML <html>    --开始标签 <head> 网页上的控制信息 <title>页面标题</title> </head> ...

  6. php中文乱码问题

    HTML中文乱码问题的解决方法. 比如有个index.html的页面(这里是指真正的静态页面,修改服务器的……伪静态的请看方案B) 1.在head标签里面加入这句 <head> <m ...

  7. coursera机器学习笔记-多元线性回归,normal equation

    #对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...

  8. SQL Server调优系列进阶篇(查询语句运行几个指标值监测)

    前言 上一篇我们分析了查询优化器的工作方式,其中包括:查询优化器的详细运行步骤.筛选条件分析.索引项优化等信息. 本篇我们分析在我们运行的过程中几个关键指标值的检测. 通过这些指标值来分析语句的运行问 ...

  9. EF Power Tools的Reverse Engineer Code First逆向生成Model时处理计算字段

    VS2013上使用EF Power Tools的Reverse Engineer Code First逆向生成Model时,没有处理计算字段.在保存实体时会出现错误. 可以通过修改Mapping.tt ...

  10. IIS 500.19 错误

    HTTP 错误 500.19 - Internal Server Error 错误代码 0x80070021 配置错误 不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定是默 ...