找到字符,返回字符串位置。没有找到返回 -1
"aaa bbb ccc".find('aaa')
查找并替换字符串
a = 'hello word'
a.replace('word','python')
4.2.2. Convert str to bytes in python
>>> b = str.encode(y)
>>> type(b) >>> b b’Hello World!’
To alter from bytes to str, capitalize on bytes.decode().
>>> z = b”Hello World!”
>>> y = “Hello World!”
>>> type(z)
>>> type(y)
To alter from str to bytes, capitalize on str.encode().
>>> a = bytes.decode(z)
>>> type(a)
>>> a
‘Hello World!’
# to utf-8
'BG7NYT'.encode('utf-8')
# to utf-16
'BG7NYT'.encode('utf-16')
strHello = "the length of (%s) is %d" %('Hello World',len('Hello World')) print strHello
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。