1、str.replace(word0,word1)  ##用word1替换str中所有的word0

>>> 'tea for too'.replace('too', 'two')
输出:'tea for two'

2、str.lower() ##字符串str中的字母全部转换成小写

  str.upper() ##字符串str中的字母全部转换成大写

  str.capitalize() ##字符串str中的第一个字母转换成大写

>>> 'df dfs ds'.upper()
'DF DFS DS'
>>> 'SDF SF OMP DFS'.lower()
'sdf sf omp dfs'
>>> 'df dfs ds'.capitalize()
'Df dfs ds'

3. str.split(sep) ## 把str按照sep进行切分,sep缺省时按照whilespace(space, tab, newline, return, formfeed)切分

>>> 'df dfs ds'.split()
['df', 'dfs', 'ds']
>>> 'df,dfs,ds'.split(',')
['df', 'dfs', 'ds']

----<未完待续>---------

正则表达式通配处理

>>> import re
>>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest')
输出: ['foot', 'fell', 'fastest']
>>> re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat')
输出:'cat in the hat'

【python】string functions的更多相关文章

  1. 【Python】String 字符串

    1. split() split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串 split()方法语法:str.split(str="" ...

  2. 【python】SQLAlchemy

    来源:廖雪峰 对比:[python]在python中调用mysql 注意连接数据库方式和数据操作方式! 今天发现了个处理数据库的好东西:SQLAlchemy 一般python处理mysql之类的数据库 ...

  3. 【Python】-NO.97.Note.2.Python -【Python 基本数据类型】

    1.0.0 Summary Tittle:[Python]-NO.97.Note.2.Python -[Python 基本数据类型] Style:Python Series:Python Since: ...

  4. 【Python】-NO.96.Note.2.Python -【Python 基础】

    1.0.0 Summary Tittle:[Python]-NO.95.Note.1.Python -[Python 老男孩 基础]- Style:Python Series:Python Since ...

  5. 【python】列出http://www.cnblogs.com/xiandedanteng中所有博文的标题

    代码: # 列出http://www.cnblogs.com/xiandedanteng中所有博文的标题 from bs4 import BeautifulSoup import requests u ...

  6. 【python】redis基本命令和基本用法详解

    [python]redis基本命令和基本用法详解 来自http://www.cnblogs.com/wangtp/p/5636872.html 1.redis连接 redis-py提供两个类Redis ...

  7. 【python】Leetcode每日一题-前缀树(Trie)

    [python]Leetcode每日一题-前缀树(Trie) [题目描述] Trie(发音类似 "try")或者说 前缀树 是一种树形数据结构,用于高效地存储和检索字符串数据集中的 ...

  8. 【python】Leetcode每日一题-不同的子序列

    [python]Leetcode每日一题-不同的子序列 [题目描述] 给定一个字符串 s 和一个字符串 t ,计算在 s 的子序列中 t 出现的个数. 字符串的一个 子序列 是指,通过删除一些(也可以 ...

  9. 【Python②】python之首秀

       第一个python程序 再次说明:后面所有代码均为Python 3.3.2版本(运行环境:Windows7)编写. 安装配置好python后,我们先来写第一个python程序.打开IDLE (P ...

随机推荐

  1. Code Sign error: a valid provisioning profile matching the application's Identifier 'com. sensoSource.VoiceRecorder' could not be found

    如果不是com. sensoSource.VoiceRecorder,在xxx-info.plist里Bundle identifier里替换成你的证书名 xxx是你的工程名 在Bundle iden ...

  2. linux查看系统CPU,内存,硬盘使用情况

    top查看CPU,内存使用情况 free查看硬盘使用情况

  3. jsp网页在浏览器中不显示图片_eclipse环境下配置tomcat中jsp项目的虚拟路径

    遇到的问题是这种,在jsp网页中嵌入了本地的图片,由于会用到上传到服务器的图片,所以没有放到项目里面,而是把全部图片单独放到一个文件夹里,然后打算使用绝对路径把要显示的图片显示出来.比方是放在了E盘的 ...

  4. Markdown基础以及个人经验

    前言 DFRobot论坛今日支持Markdown发帖了: [md] your content here [/md] 非常棒,再也不怕辛辛苦苦排个版,一夜回到解放前.这里介绍一下Markdown写博客发 ...

  5. bootstrap3分页

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  6. LeetCode – Copy List with Random Pointer

    A linked list is given such that each node contains an additional random pointer which could point t ...

  7. MySQL的timeout那点事

    http://www.mysqlops.com/2011/11/24/mysql_timeout.html

  8. css hack(部分)

    一.去掉图片间隙:hack1.img{ display:block: }hack2.将<div></div>与<img>写在同一行 二.ie6双倍浮向(双倍边距)出 ...

  9. git+jenkins

    开发写代码的演变 一个开发单打独斗,撸代码,开发网站,自由自在 多个开发同时开发一个网站,同时改一份代码.但是同时改一个文件会导致冲突 分支结构,每天上班第一件事克隆代码,下班前最后一件事合并代码 好 ...

  10. 多媒体开发之--- Live555 server 获取不到本地ip 全为0

    今天把wis-streamer live555 移植到8148上面跑起来了,运行testOnDemandRTSPServer的时候发现,本地IP地址居然为0.0.0.0; 于是乎就跟踪调试了下,看看它 ...