1. 设置fomat格式,如下:


2. 使用struck.unpack获取子字符串

print struct.unpack(format, 'Test astring')

来个简单的例子吧,有一个字符串'He is not very happy',处理一下,把中间的not去掉,然后再输出。




输出结果:
He is very happy
Python 天天美味系列(总)
Python 天天美味(11) - 可爱的大小写
Python 天天美味(12) - 条件判断的缩写
Python 天天美味(13) - struct.unpack
Python 天天美味(15) - Python正则表达式操作指南(re使用)(转)
...