str.capitalize()返回一个字符串,首字母大写
str.replace()替代字符
str.split()将字符串切分,返回一个列表,列表的元素是字符,默认用空格切分(把字符串切成列表)
str.join()参数是个可迭代的对象,返回的是一个字符串。
string 模块
string.capitalize()
string.replace('hello','o','O')
string
# from string import capitalize # # help(capitalize s='hello' print s.capitalize() print s # help (s.replace) s='hello,h' print s.replace('h','H') print s.replace('h','H',1) # help(str.replace) print s.split() s='hello a\tb\nc' print s.split() s1='abc' print s1.split() print s.split(' ') ip='192.168.1.1' print ip.split() print ip.split('.') print ip.split('.',1) print range (10) print ''.join([str(i) for i in range(10)])Hello
hello
Hello,H
Hello,h
['hello,h']
['hello', 'a', 'b', 'c']
['abc']
['hello', 'a\tb\nc']
['192.168.1.1']
['192', '168', '1', '1']
['192', '168.1.1']
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
0123456789
print range (10) print ''.join([str(i) for i in range(10)]) print int (''.join([str(i) for i in range(10)]))[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
0123456789
123456789