每天CookBook之Python-011

  • 使用slice截取数组和字符串
record = '....................100          .......513.25     ..........'
cost = int(record[20:32]) * float(record[40:48])
print(cost)

SHARES = slice(20, 32)
PRICE = slice(40, 48)
cost = int(record[SHARES]) * float(record[PRICE])
print(cost)
51325.0
51325.0
posted @ 2016-07-09 09:46  4Thing  阅读(85)  评论(0编辑  收藏  举报