python string
2013-03-30 21:10
10 查看
通过例子讲解python是最好的办法,利于学习,利于记忆,做好笔记
string.replace(str, old, new[, maxreplace])
string.zfill(s, width)
输出:
012345
-01234
123456
string.strip(s[, chars])
输出:
In [1]: import string
In [2]: string.strip(' hello world ')
Out[2]: 'hello world'
In [3]: string.strip(' hello world','world')
Out[3]: ' hello '
In [4]: string.strip(' hello world ')
Out[4]: 'hello world'
In [5]: string.lstrip(' hello world ')
Out[5]: 'hello world '
In [6]: string.rstrip(' hello world ')
Out[6]: ' hello world'
In [7]: string.strip('***hello world***','*')
Out[7]: 'hello world'
In [8]: print string.strip('hello world','world')
hello
string.replace(str, old, new[, maxreplace])
import string s='123456789123' print s #替换算法 string.replace(s, old, new, maxreplace) print string.replace(s, '123', '*****') print string.replace(s, '123', '*****',1) print s.replace('123',"fuck")
#输出如下: #123456789123 #*****456789***** #*****456789123 #fuck456789fuck
string.zfill(s, width)
import string print string.zfill("12345", 6) print string.zfill("-1234", 6) print string.zfill("123456", 6)
输出:
012345
-01234
123456
string.strip(s[, chars])
import string print string.strip(' hello world ') print string.lstrip(' hello world ') print string.rstrip(' hello world ') print string.strip('***hello world***','*') print string.strip('hello world','world')
输出:
In [1]: import string
In [2]: string.strip(' hello world ')
Out[2]: 'hello world'
In [3]: string.strip(' hello world','world')
Out[3]: ' hello '
In [4]: string.strip(' hello world ')
Out[4]: 'hello world'
In [5]: string.lstrip(' hello world ')
Out[5]: 'hello world '
In [6]: string.rstrip(' hello world ')
Out[6]: ' hello world'
In [7]: string.strip('***hello world***','*')
Out[7]: 'hello world'
In [8]: print string.strip('hello world','world')
hello
相关文章推荐
- python HTMLParser
- python md5使用例子
- Python 调试:pdb
- python学习笔记(一)——入门
- Python Cookbook (2) 文件
- python -- arp欺骗工具
- 无需WEIBO官方API实现自动发微博
- Python 2.7.3 将列表中文数据写入文件
- Python开发:关于__name__
- python 多线程采集网页
- Python开发:关于__name__
- Python中用Ctrl+C终止多线程程序的问题解决
- Python Cookbook (1) 文本
- python多线程采集原理测试
- get os type with python
- mac下用vim打造python IDE之三 —— Tmux
- 【原创翻译】理解python的with语句
- python的库
- 关于python的一些想法和疑惑
- Python学习笔记(五)