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. Please configure Spring facet or use 'Create Default Context' to add one including all unmapped files.

    有时候我们刚进入 Intellij IDEA时会出现这样一个情况,原因是IDEA没有找到spring的配置文件,我们需要添加spring文件给idea管理 参考: 1.https://www.jetb ...

  2. npm、yarn、pnpm

    它们都是当前主流的包管理工具 pnpm:https://github.com/pnpm/pnpm yarn: https://github.com/yarnpkg/yarn npm: https:// ...

  3. IOS 教你玩转UITableViewController和TableView

    iphone和Ipad开发中UITableViewController和TableView应该是用得比較多得控件. 可是你是会由于写这些控件写得多了而厌烦. 全部怎么让这个控件一直能用.怎么让这个控件 ...

  4. DICOM:DICOM Print 服务详细介绍

      目录(?)[-] 背景 DICOM Print服务数据流 DICOM Print服务各部分关系 DICOM Print服务具体实现   背景: 昨天专栏中发表了一篇关于DICOM Print的博文 ...

  5. stateMachine 相关知识

    一个state的基本构造,processMessage 以及可选的enter exit 和getName. processMessager是用于处理数据. enter 和exit 则是类似于 面向编程 ...

  6. Win7安装软件,界面上中文显示乱码的解决方案

    “Control panel”->"Clock,Language and Region"->"Region and Language"->第四 ...

  7. 浅谈MySQL外键

    http://www.xiaoxiaozi.com/2009/07/12/1158/ 像MySQL这样的关系型数据库管理系统,它们的基础是在数据库的表之间创建关系的能力.通过方便地在不同表中建立记录到 ...

  8. 关于mysql的表名/字段名/字段值是否区分大小写的问题

    http://www.2cto.com/database/201202/121253.html 1.mysql默认情况下是否区分大小写,使用show Variables like '%table_na ...

  9. 解决"Subquery returns more than 1 row"sql查询错误

    http://blog.csdn.net/c517984604/article/details/7052186 [Err] 1242 - Subquery returns more than 1 ro ...

  10. Unsupported major.minor version (jdk版本错误)解决方案 办法

    如果你遇到了 Unsupported major.minor version ,请认真看一下,说不定会有帮助. 我花两个小时总结的经验,你可能10分钟就得到了. ^**^ 一.错误现象: 当改变了jd ...