1.首字母大写

>>> s = 'yuanzhumuban'
>>> s.capitalize()
'yuanzhumuban'

    2.replace,替换

>>> s = 'my name is yuanzhumuban, age is 20'
>>> s
'my name is yuanzhumuban, age is 20'
>>> s.replace( '20', '30' )
'my name is yuanzhumuban, age is 30'
>>> s
'my name is yuanzhumuban, age is 20'
>>>

     查帮助:

>>> help( str.replace )    

如果是面向过程的函数用法,直接help( 函数名 ),如help( abs )

用法说明:

replace(...)
S.replace(old, new[, count]) -> string Return a copy of string S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced.

   接受3个参数,第一个需要替换的字符,第二个用什么字符去替换,第三个替换的次数,如果不传,默认全部替换

 str = '121212'
str.replace( '1', 'g' )
'g2g2g2'
str.replace( '1', 'g', 1 )
'g21212'
str.replace( '1', 'g', 2 )
'g2g212'
str.replace( '1', 'g', 3 )
'g2g2g2'

  3.split:切割:

 1 >>> ip='127.0.0.1'
2 >>> ip
3 '127.0.0.1'
4 >>> ip.split( '.' )
5 ['127', '0', '0', '1']
6 >>> ip.split( '.', 1 )
7 ['127', '0.0.1']
8 >>> ip.split( '.', 2 )
9 ['127', '0', '0.1']
10 >>> ip.split( '.', 3 )
11 ['127', '0', '0', '1']
12 >>>

4.用string模块,用法如下:

1 >>> import string
2 >>> help( string.capitalize )
3
4 >>> s = 'ghostwu'
5 >>> string.capitalize( s )
6 'Ghostwu'

  

1 >>> import string
2 >>> s = 'my name is ghostwu, age is 20'
3 >>> string.replace( s, '20', '30' )
4 'my name is ghostwu, age is 30'
5 >>> ip
6 '127.0.0.1'
7 >>> string.split( ip, '.' )
8 ['127', '0', '0', '1']
9 >>> string.split( ip, '.', 1 )
10 ['127', '0.0.1']
11 >>>

  

最新文章

  1. Codeforces 刷水记录
  2. 无废话ExtJs 入门教程十七[列表:GridPanel]
  3. 双模蓝牙CC2564调试笔记
  4. Openlayers自定义简单popup
  5. AdjustWindowRect与AdjustWindowRectEx
  6. 第二次作业——C++学习
  7. Linggle: 英语写作学习搜索引擎
  8. 批处理命令 - for
  9. [转载]非常完善的Log4net详细说明
  10. poj2104
  11. 向ibus-table-wubi里添加属于自己的输入法(98五笔)
  12. Android dialog 问题
  13. OpenStack使用Bosh部署CloudFoundry(一)—准备OpenStack环境
  14. JavaScript 多级联动浮动(下拉)菜单 (第二版)
  15. C++学习(二) 入门篇
  16. 发布开源库到JCenter所遇到的一些问题记录
  17. JAVA中AWT编程
  18. <知识整理>树--堆及其应用
  19. 20165319 Exp1 PC平台逆向破解
  20. Shell学习之条件测试(四)

热门文章

  1. Python 内置函数--range() xrange()
  2. Netty原理架构解析
  3. PAT(B) 1035 插入与归并(Java)
  4. TensorFlow学习笔记(1)—— 基本概念与框架
  5. nginx配置比较杂乱的总结
  6. Selenium 配置IE浏览器
  7. 关于PATCH与PUT的区别
  8. tkinter python(图形开发界面) 转自:渔单渠
  9. Luogu4705 玩游戏 分治FFT
  10. NIO(2):Channel