python.str
- 字符串append
- 切片
- format
- 字符串与unicode
一.字符串append:例如 s = 'abc'+'bxc'
二.切片:
s = 'abcdefgh'[:2] #s = 'ab'
s = 'abcdefgh'[-2:] #s = 'gh'
s = 'abc'[:100] #s = 'abc'
s = 'abc'[100:] #error
s = 'abcdefgh'[:2] #s = 'ab' s = 'abcdefgh'[-2:] #s = 'gh' s = 'abc'[:100] #s = 'abc' s = 'abc'[100:] #error
三.format
s = 'i love %s'%('you',) #'i love you' s = 'i love {0},{1},{2}'.format('you','you','you') #'i love you,you,you' s = 'i love {2},{0},{1}'.format('me','you','qiu') #'i love qiu,me,you' s = 'i love %what'.format(what='python')#'i love python'
四.字符串与unicode:
string.decode => unicode unicode.encode =>string