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 Studio 上面关于 update 和 commit 小箭头的消失
问题: android studio 在关联 SVN 或者 git 服务后,会在工具栏出现 update 和 commit 小箭头 如图: 但是,有时你打开工程的时候,发现这两个小箭头却消失不见了 如 ...
- Facebook开源动画库 POP-POPDecayAnimation运用
关于POPDecayAnimation的介绍先引用别人写的一些内容,基本上把它的一些注意点都说明了: Decay Animation 就是 POP 提供的另外一个非常特别的动画,他实现了一个衰减的效果 ...
- 【原】iOS:一种直接修改frame的某个属性的方法
在iOS中view的frame属性使用地太频繁了,尤其是调UI的时候.我们知道,正常情况下我们无法对frame的某个属性(x,y,width,height等)进行单独修改,比如: someView.f ...
- Spring为某个属性注入值或为某个方法的返回值
项目中用到需要初始化一些数据,Spring提供了filed的值注入和method的返回值注入. 一.Field值的注入 filed值注入需要使用org.springframework.beans.fa ...
- 深入理解Angular中的$Apply()以及$Digest()
$apply()和$digest()在AngularJS中是两个核心概念,但是有时候它们又让人困惑.而为了了解AngularJS的工作方式,首先需要了解$apply()和$digest()是如何工作的 ...
- 《Google想出了一个决定人员晋升的算法,然后就没有然后了......》有感
Prasad Setty 是 Google People Analytics 团队的副总裁.7 年前 Google 成立的这支团队的职责是收集和利用数据来支撑公司的管理实践.其使命很简单,即基于数据和 ...
- NuGet学习笔记2——使用图形化界面打包自己的类库
NuGet相对于我们最重要的功能是能够搭建自己的NuGet服务器,实现公司内部类库的轻松共享更新.在安装好NuGet扩展后,我们已经能够通过NuGet轻松下载自己需要的类库,下面来说一说如何将自己的项 ...
- SQL Server 连接超时案例一则
上周六,一工厂系统管理员反馈一数据库连接不上,SSMS连接数据库报"连接超时时间已到.在尝试使用预登录握手确认时超过了此超时时间.......", 如下截图所示: 另外远程连接也连 ...
- ORACLE手工删除数据库
很多人习惯用ORACLE的DBCA工具创建.删除数据库,这里总结一下手工删除数据库实验的步骤,文中大量参考了乐沙弥的手动删除ORACLE数据库这篇博客的内容,当然还有Oracle官方相关文档.此处实验 ...
- [Linux 维护]收集centos系统性能指标
#!/bin/bash # awk 'END{print}' get the last row iplist=$(cat ~/fanr/shell/Weekly/ip.list) for _IP in ...