1. 重复输出字符串
print('x' * 20)
输出:xxxxxxxxxxxxxxxxxxxx
2. 通过索引获取字符串
print('hello world'[2:5])
print('e' in 'hello world')
print('%s world'%'hello')
a = 'hello 'b = ' world'c = a + bprint(c)
a = 'hello'b = ' world'c = ' '.join([a,b])print(c)
a = 'www.baidu.com'print(a.count('w'))
a = "www.baidu.com"b = a.center(50, '*')print(b)
a = 'www.baidu.com'print(a.startswith('www'))
a = 'www.baidu.com'b = a.find('u')print(b)
a = '{0}.baidu.{1}'.format('www', 'com')print(a) #输出www.baidu.comstring = 'hello world {xxx} {ppp}'b = string.format(xxx='xxx', ppp = 'ppp')print(b) #输出hello world xxx pppc = string.format_map({'xxx':'xxx', 'ppp':'ppp'})print(c) #输出:hello world xxx ppp
a = 'Wang Da Bai'print(a.lower())
a = 'Wang Da Bai'print(a.upper())
a = 'wang da bai 'print(a.strip()) #去除尾部空格
a = "wang da bai"b = a.replace('w', '*')print(b) #输出: *ang da baic = 'wangdabai'.replace('d', 'xxxxxx', 1)print(c) #输出 wangxxxxxxabai


